Given a doubly-linked list of positive integers. The task is to print the given doubly linked list data in reverse order.
Input: List = 1 <=> 2 <=> 3 <=> 4 <=> 5 Output: 5 4 3 2 1 Input: 10 <=> 20 <=> 30 <=> 40 Output: 40 30 20 10
- Take a pointer to point to head of the doubly linked list.
- Now, start traversing through the linked list till the end.
- After reaching last node, start traversing in backward direction and simultaneously print the node->data.
Below is the implementation of the above approach:
Linked List elements in reverse order : 2 4 8 10
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.
- 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
- Reverse a Doubly linked list using recursion
- Reverse a Doubly Linked List | Set-2
- Reverse a Doubly Linked List | Set 4 (Swapping Data)
- Reverse a doubly linked list in groups of given size
- Reverse a doubly circular linked list
- Reverse a Doubly Linked List
- Print the last k nodes of the linked list in reverse order | Recursive approach
- Print the last k nodes of the linked list in reverse order | Iterative Approaches
- Merge K sorted Doubly Linked List in Sorted Order
- Construct a Doubly linked linked list from 2D Matrix
- Merge two sorted linked lists such that merged list is in reverse order
- An interesting method to print reverse of a linked list
- Print reverse of a Linked List without extra space and modifications
- Print Reverse a linked list using Stack
- Print reverse of a Linked List without actually reversing
- Memory efficient doubly linked list
- Delete a node in 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 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.