How do you reverse a double linked list? | SoloLearn: Learn to code for FREE!

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!

5/17/2020 8:38:17 PM

David Quichocho

1 Answer

New 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.