Reverse a singly linked list (recursively)

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

Sponsored: has published a chatbot, who can chat with you and help you find apartments in San Francisco and Bay area. Check it out:

Recursive solution:
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 }
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: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s