Write a program to reverse the given Doubly Linked List.
See below diagrams for example.
(a) Original Doubly Linked List
(b) Reversed Doubly Linked List
Approach: In the previous post, doubly linked list is being reversed by swapping prev and next pointers for all nodes, changing prev of the head (or start) and then changing the head pointer in the end. In this post, we create a push function that adds the given node at the beginning of the given list. We traverse the original list and one by one pass the current node pointer to the push function. This process will reverse the list. Finally return the new head of this reversed list.
Original list: 10 8 4 2 Reversed list: 2 4 8 10
Time Complexity: O(n).
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.
- Reverse a Doubly Linked List
- Reverse a Doubly linked list using recursion
- Reverse a doubly circular linked list
- Print Doubly Linked list in Reverse Order
- Reverse a Doubly Linked List | Set 4 (Swapping Data)
- Reverse a doubly linked list in groups of given size
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Difference between Singly linked list and Doubly linked list
- Construct a Doubly linked linked list from 2D Matrix
- Doubly Linked List Tutorial
- QuickSort on Doubly Linked List
- Python | Stack using Doubly Linked List
- Delete all the even nodes from a Doubly Linked List
- Implementation of Deque using doubly linked list
- Merge Sort for Doubly Linked List
- Priority Queue using doubly linked list
- Doubly Linked List | Set 1 (Introduction and Insertion)
- Doubly Circular Linked List | Set 2 (Deletion)
- Bubble Sort On Doubly Linked List
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.