Last Updated: 19 January, 2025 5 Mins
In this tutorial we are going to talk about how to reverse a doubly linked list using the Java program.
In order to reverse a doubly linked list, we need to iterate through the list while swapping the next and previous pointers of each node. Once we reach the end of the list, the head pointer will point to the last node of the list.
Let's understand the reverse of a doubly linked list with the given example below:
Class: Node
Class: ReverseDoublyLinkedList
Output
Original doubly linked list: 10 20 30 40 50 Reversed doubly linked list: 50 40 30 20 10
Time Complexity: O(n)
Auxiliary Space: O(n)
here n means the total number of nodes in a doubly linked list.
That's all, guys. I hope this article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com