Be the first user to complete this post
|
Add to List |
31. Reverse a Linked List Using Recursion
Objective: Reverse the given linked list using recursion
Example:
Original List :->10->8->6->4->2 Reversed List :->2->4->6->8->10
Approach:
Recursion:
- Traverse till the end of list through recursion.
- Make the last node as head.
- Now you are at the end of the list and rest of the nodes are stores in a stack
- Now while coming back, each node will pop out from the stack in reverse order
- take these nodes and start pointing it to next node coming out of stack.
Output:
Original List : ->10->8->6->4->2 Reversed List : ->2->4->6->8->10