Sunday, July 12, 2009

C++ linked list?

Hello I have home work in c++: write function whose delete those elements who next element is even. for example i have this list: 4 2 2, the result of this function mus be: 2. other example: 4 1 2 2, result: 4 2. I write such function, but with this examples my function make error.. Where can be error in this function?:





void remake(elem *%26amp;first)


{


elem *curr=first;


elem *prev=NULL;


elem *pprev=NULL;





while(curr!=NULL)


{


pprev=prev;


prev=curr;


curr=curr-%26gt;next;





if(curr!=NULL)


{


if(curr-%26gt;n%2==0)


{


if(pprev==NULL)


{


delete prev;


first=curr;


prev=curr;


}


else


{


pprev-%26gt;next=curr;


delete prev;


prev=pprev;


}


}


}


}


};

C++ linked list?
That is lot of homework.


No comments:

Post a Comment