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).
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Difference between Singly linked list and Doubly linked list
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Construct a Doubly linked linked list from 2D Matrix
- QuickSort on Doubly Linked List
- Doubly Linked List Tutorial
- Insertion Sort for Doubly Linked List
- Merge Sort for Doubly Linked List
- Sort the biotonic doubly linked list | Set-2
- Priority Queue using doubly linked list
- Rotate Doubly linked list by N nodes
- Python | Stack using Doubly Linked List
- Python | Queue using Doubly Linked List
- Doubly Linked List | Set 1 (Introduction and Insertion)
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.