Reverse a Linked List


/ Published in: C++
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.