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 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