Implementation of singly and doubly linked lists. Because it makes no sense to do so, the 'next' and 'prev' pointers are not hidden from you and can be manipulated directly for efficiency.
Types
DoublyLinkedNodeObj[T] = object next*, prev*: ref DoublyLinkedNodeObj[T] value*: T
- a node a doubly linked list consists of Source
DoublyLinkedNode[T] = ref DoublyLinkedNodeObj[T]
- Source
SinglyLinkedNodeObj[T] = object next*: ref SinglyLinkedNodeObj[T] value*: T
- a node a singly linked list consists of Source
SinglyLinkedNode[T] = ref SinglyLinkedNodeObj[T]
- Source
SinglyLinkedList[T] = object head*, tail*: SinglyLinkedNode[T]
- a singly linked list Source
DoublyLinkedList[T] = object head*, tail*: DoublyLinkedNode[T]
- a doubly linked list Source
SinglyLinkedRing[T] = object head*, tail*: SinglyLinkedNode[T]
- a singly linked ring Source
DoublyLinkedRing[T] = object head*: DoublyLinkedNode[T]
- a doubly linked ring Source
Procs
proc initSinglyLinkedList[T](): SinglyLinkedList[T]
- creates a new singly linked list that is empty. Source
proc initDoublyLinkedList[T](): DoublyLinkedList[T]
- creates a new doubly linked list that is empty. Source
proc initSinglyLinkedRing[T](): SinglyLinkedRing[T]
- creates a new singly linked ring that is empty. Source
proc initDoublyLinkedRing[T](): DoublyLinkedRing[T]
- creates a new doubly linked ring that is empty. Source
proc newDoublyLinkedNode[T](value: T): DoublyLinkedNode[T]
- creates a new doubly linked node with the given value. Source
proc newSinglyLinkedNode[T](value: T): SinglyLinkedNode[T]
- creates a new singly linked node with the given value. Source
proc `$`[T](L: SinglyLinkedList[T]): string
- turns a list into its string representation. Source
proc `$`[T](L: DoublyLinkedList[T]): string
- turns a list into its string representation. Source
proc `$`[T](L: SinglyLinkedRing[T]): string
- turns a list into its string representation. Source
proc `$`[T](L: DoublyLinkedRing[T]): string
- turns a list into its string representation. Source
proc find[T](L: SinglyLinkedList[T]; value: T): SinglyLinkedNode[T]
- searches in the list for a value. Returns nil if the value does not exist. Source
proc find[T](L: DoublyLinkedList[T]; value: T): DoublyLinkedNode[T]
- searches in the list for a value. Returns nil if the value does not exist. Source
proc find[T](L: SinglyLinkedRing[T]; value: T): SinglyLinkedNode[T]
- searches in the list for a value. Returns nil if the value does not exist. Source
proc find[T](L: DoublyLinkedRing[T]; value: T): DoublyLinkedNode[T]
- searches in the list for a value. Returns nil if the value does not exist. Source
proc contains[T](L: SinglyLinkedList[T]; value: T): bool {.inline.}
- searches in the list for a value. Returns false if the value does not exist, true otherwise. Source
proc contains[T](L: DoublyLinkedList[T]; value: T): bool {.inline.}
- searches in the list for a value. Returns false if the value does not exist, true otherwise. Source
proc contains[T](L: SinglyLinkedRing[T]; value: T): bool {.inline.}
- searches in the list for a value. Returns false if the value does not exist, true otherwise. Source
proc contains[T](L: DoublyLinkedRing[T]; value: T): bool {.inline.}
- searches in the list for a value. Returns false if the value does not exist, true otherwise. Source
proc prepend[T](L: var SinglyLinkedList[T]; n: SinglyLinkedNode[T]) {.inline.}
- prepends a node to L. Efficiency: O(1). Source
proc prepend[T](L: var SinglyLinkedList[T]; value: T) {.inline.}
- prepends a node to L. Efficiency: O(1). Source
proc append[T](L: var DoublyLinkedList[T]; n: DoublyLinkedNode[T])
- appends a node n to L. Efficiency: O(1). Source
proc append[T](L: var DoublyLinkedList[T]; value: T)
- appends a value to L. Efficiency: O(1). Source
proc prepend[T](L: var DoublyLinkedList[T]; n: DoublyLinkedNode[T])
- prepends a node n to L. Efficiency: O(1). Source
proc prepend[T](L: var DoublyLinkedList[T]; value: T)
- prepends a value to L. Efficiency: O(1). Source
proc remove[T](L: var DoublyLinkedList[T]; n: DoublyLinkedNode[T])
- removes n from L. Efficiency: O(1). Source
proc append[T](L: var SinglyLinkedRing[T]; n: SinglyLinkedNode[T])
- appends a node n to L. Efficiency: O(1). Source
proc append[T](L: var SinglyLinkedRing[T]; value: T)
- appends a value to L. Efficiency: O(1). Source
proc prepend[T](L: var SinglyLinkedRing[T]; n: SinglyLinkedNode[T])
- prepends a node n to L. Efficiency: O(1). Source
proc prepend[T](L: var SinglyLinkedRing[T]; value: T)
- prepends a value to L. Efficiency: O(1). Source
proc append[T](L: var DoublyLinkedRing[T]; n: DoublyLinkedNode[T])
- appends a node n to L. Efficiency: O(1). Source
proc append[T](L: var DoublyLinkedRing[T]; value: T)
- appends a value to L. Efficiency: O(1). Source
proc prepend[T](L: var DoublyLinkedRing[T]; n: DoublyLinkedNode[T])
- prepends a node n to L. Efficiency: O(1). Source
proc prepend[T](L: var DoublyLinkedRing[T]; value: T)
- prepends a value to L. Efficiency: O(1). Source
proc remove[T](L: var DoublyLinkedRing[T]; n: DoublyLinkedNode[T])
- removes n from L. Efficiency: O(1). Source
Iterators
iterator items[T](L: DoublyLinkedList[T]): T
- yields every value of L. Source
iterator items[T](L: SinglyLinkedList[T]): T
- yields every value of L. Source
iterator items[T](L: SinglyLinkedRing[T]): T
- yields every value of L. Source
iterator items[T](L: DoublyLinkedRing[T]): T
- yields every value of L. Source
iterator mitems[T](L: var DoublyLinkedList[T]): var T
- yields every value of L so that you can modify it. Source
iterator mitems[T](L: var SinglyLinkedList[T]): var T
- yields every value of L so that you can modify it. Source
iterator mitems[T](L: var SinglyLinkedRing[T]): var T
- yields every value of L so that you can modify it. Source
iterator mitems[T](L: var DoublyLinkedRing[T]): var T
- yields every value of L so that you can modify it. Source
iterator nodes[T](L: SinglyLinkedList[T]): SinglyLinkedNode[T]
- iterates over every node of x. Removing the current node from the list during traversal is supported. Source
iterator nodes[T](L: DoublyLinkedList[T]): DoublyLinkedNode[T]
- iterates over every node of x. Removing the current node from the list during traversal is supported. Source
iterator nodes[T](L: SinglyLinkedRing[T]): SinglyLinkedNode[T]
- iterates over every node of x. Removing the current node from the list during traversal is supported. Source
iterator nodes[T](L: DoublyLinkedRing[T]): DoublyLinkedNode[T]
- iterates over every node of x. Removing the current node from the list during traversal is supported. Source