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 in groups of given size
- Reverse a Doubly Linked List | Set 4 (Swapping Data)
- 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
- Bubble Sort On Doubly Linked List
- Rotate Doubly linked list by N nodes
- Implementation of Deque using doubly linked list
- Merge Sort for Doubly Linked List
- Insertion Sort for 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.