diff --git a/src/lib/algorithms/data-structures.ts b/src/lib/algorithms/data-structures.ts index 95eea38..5b4e7b3 100644 --- a/src/lib/algorithms/data-structures.ts +++ b/src/lib/algorithms/data-structures.ts @@ -69,11 +69,15 @@ class LinkedList { if (!this.head) return; if (this.head.value === value) { this.head = this.head.next; + if (!this.head) this.tail = null; return; } let current = this.head; while (current.next) { if (current.next.value === value) { + if (current.next === this.tail) { + this.tail = current; + } current.next = current.next.next; return; }