Reverse a singly linked list (recursively)

What is the most efficient method to reverse a Singly Linked List? 

Recursive solution:
C++:
01 Node* reverse_recursive(Node* head)
02 {
03    if(head->next==NULL)
04        return head;
05    Node* tmp=head->next;
06    head->next=NULL;
07    Node* hd=reverse_recursive(tmp);
08    tmp->next=head;
09    return hd;
10 }
Advertisements
This entry was posted in Array and linked list, Recursive. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s