Singly & Doubly Linked Lists
Singly and Doubly Linked list
Singly Linked list
removeFromTail() {
if (!this.head) return
this.#length--;
if (this.head === this.tail) {
// Only one node in the list
const data = this.head.data;
this.head = null;
this.tail = null;
return data;
}
let currentNode = this.head;
while (currentNode.next !== this.tail) {
currentNode = currentNode.next;
}
const data = this.tail.data;
currentNode.next = null;
this.tail = currentNode;
return data;
}Doubly Linked list
tradeoffs
Cycles
Check to see if a linked list is a cycle
Last updated