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 Edit
DoublyLinkedNode[T] = ref DoublyLinkedNodeObj[T]
- Source Edit
SinglyLinkedNodeObj[T] = object next*: ref SinglyLinkedNodeObj[T] value*: T
- a node a singly linked list consists of Source Edit
SinglyLinkedNode[T] = ref SinglyLinkedNodeObj[T]
- Source Edit
SinglyLinkedList[T] = object head*, tail*: SinglyLinkedNode[T]
- a singly linked list Source Edit
DoublyLinkedList[T] = object head*, tail*: DoublyLinkedNode[T]
- a doubly linked list Source Edit
SinglyLinkedRing[T] = object head*, tail*: SinglyLinkedNode[T]
- a singly linked ring Source Edit
DoublyLinkedRing[T] = object head*: DoublyLinkedNode[T]
- a doubly linked ring Source Edit
Procs
proc initSinglyLinkedList[T](): SinglyLinkedList[T]
- creates a new singly linked list that is empty. Source Edit
proc initDoublyLinkedList[T](): DoublyLinkedList[T]
- creates a new doubly linked list that is empty. Source Edit
proc initSinglyLinkedRing[T](): SinglyLinkedRing[T]
- creates a new singly linked ring that is empty. Source Edit
proc initDoublyLinkedRing[T](): DoublyLinkedRing[T]
- creates a new doubly linked ring that is empty. Source Edit
proc newDoublyLinkedNode[T](value: T): DoublyLinkedNode[T]
- creates a new doubly linked node with the given value. Source Edit
proc newSinglyLinkedNode[T](value: T): SinglyLinkedNode[T]
- creates a new singly linked node with the given value. Source Edit
proc `$`[T](L: SinglyLinkedList[T]): string
- turns a list into its string representation. Source Edit
proc `$`[T](L: DoublyLinkedList[T]): string
- turns a list into its string representation. Source Edit
proc `$`[T](L: SinglyLinkedRing[T]): string
- turns a list into its string representation. Source Edit
proc `$`[T](L: DoublyLinkedRing[T]): string
- turns a list into its string representation. Source Edit
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 Edit
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 Edit
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 Edit
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 Edit
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 Edit
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 Edit
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 Edit
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 Edit
proc prepend[T](L: var SinglyLinkedList[T]; n: SinglyLinkedNode[T]) {.
inline.}- prepends a node to L. Efficiency: O(1). Source Edit
proc prepend[T](L: var SinglyLinkedList[T]; value: T) {.
inline.}- prepends a node to L. Efficiency: O(1). Source Edit
proc append[T](L: var DoublyLinkedList[T]; n: DoublyLinkedNode[T])
- appends a node n to L. Efficiency: O(1). Source Edit
proc append[T](L: var DoublyLinkedList[T]; value: T)
- appends a value to L. Efficiency: O(1). Source Edit
proc prepend[T](L: var DoublyLinkedList[T]; n: DoublyLinkedNode[T])
- prepends a node n to L. Efficiency: O(1). Source Edit
proc prepend[T](L: var DoublyLinkedList[T]; value: T)
- prepends a value to L. Efficiency: O(1). Source Edit
proc remove[T](L: var DoublyLinkedList[T]; n: DoublyLinkedNode[T])
- removes n from L. Efficiency: O(1). Source Edit
proc append[T](L: var SinglyLinkedRing[T]; n: SinglyLinkedNode[T])
- appends a node n to L. Efficiency: O(1). Source Edit
proc append[T](L: var SinglyLinkedRing[T]; value: T)
- appends a value to L. Efficiency: O(1). Source Edit
proc prepend[T](L: var SinglyLinkedRing[T]; n: SinglyLinkedNode[T])
- prepends a node n to L. Efficiency: O(1). Source Edit
proc prepend[T](L: var SinglyLinkedRing[T]; value: T)
- prepends a value to L. Efficiency: O(1). Source Edit
proc append[T](L: var DoublyLinkedRing[T]; n: DoublyLinkedNode[T])
- appends a node n to L. Efficiency: O(1). Source Edit
proc append[T](L: var DoublyLinkedRing[T]; value: T)
- appends a value to L. Efficiency: O(1). Source Edit
proc prepend[T](L: var DoublyLinkedRing[T]; n: DoublyLinkedNode[T])
- prepends a node n to L. Efficiency: O(1). Source Edit
proc prepend[T](L: var DoublyLinkedRing[T]; value: T)
- prepends a value to L. Efficiency: O(1). Source Edit
proc remove[T](L: var DoublyLinkedRing[T]; n: DoublyLinkedNode[T])
- removes n from L. Efficiency: O(1). Source Edit
Iterators
iterator items[T](L: DoublyLinkedList[T]): T
- yields every value of L. Source Edit
iterator items[T](L: SinglyLinkedList[T]): T
- yields every value of L. Source Edit
iterator items[T](L: SinglyLinkedRing[T]): T
- yields every value of L. Source Edit
iterator items[T](L: DoublyLinkedRing[T]): T
- yields every value of L. Source Edit
iterator mitems[T](L: var DoublyLinkedList[T]): var T
- yields every value of L so that you can modify it. Source Edit
iterator mitems[T](L: var SinglyLinkedList[T]): var T
- yields every value of L so that you can modify it. Source Edit
iterator mitems[T](L: var SinglyLinkedRing[T]): var T
- yields every value of L so that you can modify it. Source Edit
iterator mitems[T](L: var DoublyLinkedRing[T]): var T
- yields every value of L so that you can modify it. Source Edit
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 Edit
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 Edit
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 Edit
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 Edit