mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 23:54:19 +00:00
add SinglyLinkedList.append procs
This commit is contained in:
@@ -140,11 +140,26 @@ proc contains*[T](L: SomeLinkedCollection[T], value: T): bool {.inline.} =
|
||||
## exist, true otherwise.
|
||||
result = find(L, value) != nil
|
||||
|
||||
proc append*[T](L: var SinglyLinkedList[T],
|
||||
n: SinglyLinkedNode[T]) {.inline.} =
|
||||
## appends a node `n` to `L`. Efficiency: O(1).
|
||||
n.next = nil
|
||||
if L.tail != nil:
|
||||
assert(L.tail.next == nil)
|
||||
L.tail.next = n
|
||||
L.tail = n
|
||||
if L.head == nil: L.head = n
|
||||
|
||||
proc append*[T](L: var SinglyLinkedList[T], value: T) {.inline.} =
|
||||
## appends a value to `L`. Efficiency: O(1).
|
||||
append(L, newSinglyLinkedNode(value))
|
||||
|
||||
proc prepend*[T](L: var SinglyLinkedList[T],
|
||||
n: SinglyLinkedNode[T]) {.inline.} =
|
||||
## prepends a node to `L`. Efficiency: O(1).
|
||||
n.next = L.head
|
||||
L.head = n
|
||||
if L.tail == nil: L.tail = n
|
||||
|
||||
proc prepend*[T](L: var SinglyLinkedList[T], value: T) {.inline.} =
|
||||
## prepends a node to `L`. Efficiency: O(1).
|
||||
|
||||
Reference in New Issue
Block a user