mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-04 02:44:44 +00:00
Fix remove on last node of singly-linked list [backport:1.6] (#19353)
This commit is contained in:
@@ -258,5 +258,18 @@ template main =
|
||||
a.add(2)
|
||||
doAssert a.toSeq == @[1, 2]
|
||||
|
||||
block RemoveLastNodeFromSinglyLinkedList:
|
||||
var list = initSinglyLinkedList[string]()
|
||||
let n1 = newSinglyLinkedNode("sonic")
|
||||
let n2 = newSinglyLinkedNode("the")
|
||||
let n3 = newSinglyLinkedNode("tiger")
|
||||
let n4 = newSinglyLinkedNode("hedgehog")
|
||||
list.add(n1)
|
||||
list.add(n2)
|
||||
list.add(n3)
|
||||
list.remove(n3)
|
||||
list.add(n4)
|
||||
doAssert list.toSeq == @["sonic", "the", "hedgehog"]
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user