How do you reverse a double linked list? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do you reverse a double linked list?

How would you reverse a double linked list (turn 1,2,3 to 3,2,1) while keeping O(n) time and without creating new nodes? Could use some help on this. Thanks in advance!

17th May 2020, 8:38 PM
David Quichocho
David Quichocho - avatar
1 Answer
+ 1
Maybe you could iterate through every node and switch the links to the next and the prev node. And when you reach the last node you set the last node as root.
17th May 2020, 8:53 PM
Jnn
Jnn - avatar