Given pointer to the head node of a linked list, the task is to recursively reverse the linked list. We need to reverse the list by changing links between nodes.
Input : Head of following linked list 1->2->3->4->NULL Output : Linked list should be changed to, 4->3->2->1->NULL Input : Head of following linked list 1->2->3->4->5->NULL Output : Linked list should be changed to, 5->4->3->2->1->NULL Input : NULL Output : NULL Input : 1->NULL Output : 1->NULL
- We return the pointer of next node to his previous(current) node and then make the previous node as the next node of returned node and then returning the current node.
- We first traverse till the last node and making the last node as the head node of reversed linked list and then applying the above procedure in the recursive manner.
- Print reverse of a Linked List without actually reversing
- Find middle of singly linked list Recursively
- Linked List Implementation in C#
- Queue - Linked List Implementation
- Implementation of Deque using doubly linked list
- Circular Queue | Set 2 (Circular Linked List Implementation)
- Create new linked list from two given linked list with greater element at each node
- Difference between Singly linked list and Doubly linked list
- Merge a linked list into another linked list at alternate positions
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Convert singly linked list into circular linked list
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Check if a linked list is Circular Linked List
- Convert Singly Linked List to XOR Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Create a linked list from two linked lists by choosing max element at each position
- Construct a Doubly linked linked list from 2D Matrix
- Partitioning a linked list around a given value and If we don't care about making the elements of the list "stable"
- Length of longest palindrome list in a linked list using O(1) extra space
- Rotate the sub-list of a linked list from position M to N to the right by K places
We have discussed an iterative and two recursive approaches in previous post on reverse a linked list.
In this approach of reversing a linked list by passing a single pointer what we are trying to do is that we are making the previous node of the current node as his next node to reverse the linked list.
Given linked list 85 15 4 20 Reversed Linked list 20 4 15 85
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.