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).
- Reverse a Doubly Linked List
- Reverse a Doubly linked list using recursion
- Reverse a doubly circular linked list
- Reverse a Doubly Linked List | Set 4 (Swapping Data)
- Reverse a doubly linked list in groups of given size
- Print Doubly Linked list in Reverse Order
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Difference between Singly linked list and Doubly linked list
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- QuickSort on Doubly Linked List
- Priority Queue using doubly linked list
- Find pairs with given sum in doubly linked list
- Python | Stack using Doubly Linked List
- Python | Queue using Doubly Linked List
- Delete all the even nodes from a 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 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.