Hello.
I have made this program for linked list, but i have one problem with it. I want to make a function that will delete all same values I inuput in the list.
Example: if user inputs 5 I want to delete all 5 for the list.
I have tried doing this with the loop inside regular function that erase single value.
This is funnction that erases single value:
This is my attempt to make function:Code:void list::Delete (int a) { node *temp=head; if (temp==NULL) return ; if (temp->getNext()==NULL) { delete temp; head=NULL; } else { node *prev; do { if (temp->getBroj()==a) break; prev=temp; temp=temp->getNext(); }while (temp!=NULL); prev->setNext(temp->getNext()); } }
Code:else { bool change=false; node *prev; do { change=false; do { if (temp->getBroj()==a) { change=true; break; } prev=temp; temp=temp->getNext(); }while (temp!=NULL); prev->setNext(temp->getNext()); }while (!change); }
Thank you




Reply With Quote