While writing reverse method of Doubly Linked List, I observed that node swapping by Method 1 didn’t yield the expected result but Method 2 did.
Method 1
node.prev, node.next = node.next, node.prev;
Method 2
let tempNode = node.next;
node.next = node.prev;
node.prev = tempNode;
So, what is the difference between this swapping methods?
Here’s a link to the challenge