Fix remove on last node of singly-linked list [backport:1.6] (#19353)

(cherry picked from commit 955040f0f1)
This commit is contained in:
gecko
2022-01-10 09:27:59 +00:00
committed by narimiran
parent 2539d7a862
commit a90cabbe40
3 changed files with 19 additions and 0 deletions

View File

@@ -740,6 +740,8 @@ proc remove*[T](L: var SinglyLinkedList[T], n: SinglyLinkedNode[T]): bool {.disc
if prev.next == nil:
return false
prev.next = n.next
if L.tail == n:
L.tail = prev # update tail if we removed the last node
true
proc remove*[T](L: var DoublyLinkedList[T], n: DoublyLinkedNode[T]) =