From 7d6d69be1befd6419f88cffbe8406b05db1ae1e7 Mon Sep 17 00:00:00 2001 From: AngelDev2110 Date: Fri, 13 Mar 2026 12:44:52 -0600 Subject: [PATCH] Fix LinkedList tail update on removal of head and tail nodes --- src/lib/algorithms/data-structures.ts | 4 ++++ 1 file changed, 4 insertions(+) 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; }