Posted By

iTony on 11/06/07


Tagged

c classes lists pointers


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

copyleft


Reverse a Linked List


 / Published in: C++
 

this pointers are making me dizzy, so just for a reference i'll keep them here.

  1. NodePtr reversed=NULL, cur=head;
  2.  
  3. while(cur!=NULL)
  4. {
  5. //detach cur
  6. head=head->next;
  7.  
  8. //link cur to reversed list
  9. cur->next=reversed;
  10. reversed=cur;
  11.  
  12. //move cur to next node
  13. cur=head;
  14.  
  15. head=reversed;
  16. }

Report this snippet  

You need to login to post a comment.