Reverse doubly linked list
Ngày đăng:
24/12/2021
Trả lời:
0
Lượt xem:
125
In this program, we create a doubly linked list, and then reverse the list by reversing the direction of the list and print out the nodes. Show Traverse through the list by swapping the previous pointer with next pointer of each node. Then, swap the position of head and tail node that is, head of the original list will become tail of new list and tail of the original list will become head of the new list. So, the reversed list will be: Algorithm
a. reverse() will reverse the given doubly linked list.
a. display() will show all the nodes present in the list.
Program:Output: Original List:
1 2 3 4 5
Reversed List:
5 4 3 2 1
|