Please consider we have doubly linked list already created...
reverseDoublyLinkedList() {
let current = this.head;
let prev = null;
if (this.head === null || this.head.next === null) {
return this.head;
}
while (current) {
prev = current.previous;
current.previous = current.next;
current.next = prev;
current = current.previous;
}
this.head = prev.previous;
}
Top comments (0)