hmm the simplest way to destroy a whole list is to write a function that eliminates one element the list and use that in another function which has a while or for ...
something like
there you have itCode:#include <iostream.h> #include <conio.h> struct elem{int info; elem *next; };//this is a simple linked list ...there's no need for decalarting a double one you ll just complicate matters elem *f;//see that you only need the first element of the list :D ///considering you've already created the list :) void eliminate(elem *&n){ elem *r; r=n->next; n->next=n->next->next; delete r; //i've just deleted n->next :D } void main(){ for(elem *q=f;q->next;q=q->next) eliminate(q);//with the little trick i used deleteing q->next i never got to deleting p delete p;//so here i delete p :) }
so there is no need for a double linked list![]()



LinkBack URL
About LinkBacks




CornedBee