How to reverse a link list without using another link list?
Note: Linked list is singly linked list (there is only next pointer no previous pointer).
See Solution: Reverse a link list without using another linked list
Take two pointers previous and current, increment both pointers by one till current reaches at the end of the list.
![reverse linked list Reverse a Linked List](https://i1.wp.com/puzzlersworld.com/wp/wp-content/uploads/2012/11/reverse-linked-list.jpg?resize=300%2C61&ssl=1)
Reverse a Linked List
Node* reverse(Node* node) { if(node == null) return null; Node * prev = node; Node* curr = node->next; while(curr != null){ Node* tmp = curr->next; curr->next = prev; prev = curr; curr = temp; } return prev; }
Facebook Comments
awsum logic for reverse a linklist ..thankss
Thanks Rahul