mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes #25173
(cherry picked from commit 51a9ada043)
This commit is contained in:
@@ -710,6 +710,8 @@ proc remove*[T](L: var SinglyLinkedList[T], n: SinglyLinkedNode[T]): bool {.disc
|
||||
L.head = n.next
|
||||
if L.tail.next == n:
|
||||
L.tail.next = L.head # restore cycle
|
||||
if L.tail == n:
|
||||
L.tail = nil # reset tail if we removed the last node
|
||||
else:
|
||||
var prev = L.head
|
||||
while prev.next != n and prev.next != nil:
|
||||
|
||||
@@ -273,5 +273,17 @@ template main =
|
||||
list.add(n4)
|
||||
doAssert list.toSeq == @["sonic", "the", "hedgehog"]
|
||||
|
||||
|
||||
block:
|
||||
var list = initSinglyLinkedList[int]()
|
||||
|
||||
list.add(4)
|
||||
list.remove(list.head)
|
||||
|
||||
list.add(5)
|
||||
list.remove(list.head)
|
||||
|
||||
list.add(6)
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user