Given a doubly linked list containing n nodes. The problem is to reverse every group of k nodes in the list.
Prerequisite: Reverse a doubly linked list | Set-2.
Approach: Create a recursive function say reverse(head, k). This function receives the head or the first node of each group of k nodes. It reverses those group of k nodes by applying the approach discussed in Reverse a doubly linked list | Set-2. After reversing the group of k nodes the function checks whether next group of nodes exists in the list or not. If group exists then it makes a recursive call to itself with the first node of the next group and makes the necessary adjustments with the next and previous links of that group. Finally it returns the new head node of the reversed group.
Original list: 10 8 4 2 Modified list: 8 10 2 4
Time Complexity: O(n).
- Reverse a Linked List in groups of given size | Set 1
- Reverse a Linked List in groups of given size | Set 2
- Reverse a Linked List in groups of given size (Iterative Approach)
- Reverse a Doubly Linked List | Set-2
- Reverse a Doubly Linked List
- Reverse a doubly circular linked list
- Reverse a Doubly linked list using recursion
- Reverse a Doubly Linked List | Set 4 (Swapping Data)
- Print Doubly Linked list in Reverse Order
- Program to find size of Doubly Linked List
- Reverse a Linked List according to its Size
- Reverse an array in groups of given size
- Reverse an array in groups of given size | Set 2 (Variations of Set 1 )
- Difference between Singly linked list and Doubly linked list
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.