how to delete node from somewhere middle in doubly linked list
it works fine to delete from start or end. but whenever I try to delete a value from middle , it gives garbage value :( plz help ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
void dllist<T>::deletevalue2ndvalue(const T& el)
{
dlnode<T> *temp=head;
if(head==0) {
cout<<"Error! List is empty..."; return;
}
else if(head==tail)
{
delete head;
head=tail=0; return;
}
else if(head->info==el)
{
this->deletefromfront();
return;
}
else if(tail->info==el)
{
this->deletefromend();
return;
}
while(head->info!=el && head->next!=0)
{head=head->next;
}
if(head->info!=el)
{
cout<<"ERROR! value not found"<<endl; return;
}
head->previous->next=head->next;
head->next->previous=head->previous;
delete head;
head=temp;
}
|
head->previous->next=head->next;
head->next->previous=head->previous;
delete head;
why doesn't this work?
Last edited on
Topic archived. No new replies allowed.