Skip to content

Commit 3ddbc19

Browse files
committed
fix: linkedList - update tail when remove last item
1 parent f8545ef commit 3ddbc19

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

EstruturaDados/LinkedLists.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ <h1>listas ligadas ou encadeadas</h1>
117117
if (current.value === value) {
118118
if (prev) {
119119
prev.next = current.next
120+
// Se o nó removido for o tail, atualiza o tail
121+
if (current === this.tail) {
122+
this.tail = prev;
123+
}
120124
current.next = null
121125
} else {
122126
this.head = current.next
127+
// Se removemos o único elemento da lista, atualiza o tail
128+
if (current === this.tail) {
129+
this.tail = null;
130+
}
123131
current.next = null
124132
}
125133
this.#size--

0 commit comments

Comments
 (0)