Domanda di colloquio di Microsoft

Reverse a double linked list

Risposta di colloquio

Anonimo

23 set 2021

swap previous and next pointers for all nodes, change previous of the head (or start) and change the head pointer in the end. // swapping pointer let reverseDLL = (head) => { let temp = null; let current = head; while(current){ temp = current.prev; current.prev = current.next; current.next = temp; current = current.prev; } if (temp != null) { head = temp.prev; } }