remove
Remove a node from the list.
Arguments: node: Pointer to the node to be removed.
Function parameters
Parameters
- list:*DoublyLinkedList
- node:*Node
This struct contains only the prev and next pointers and not any data
Types
- Node
- This struct contains only the prev and next pointers and not any data
Functions in this namespace
Functions
- concatByMoving
- Concatenate list2 onto the end of list1, removing all entries from the former.
- append
- Insert a new node at the end of the list.
- prepend
- Insert a new node at the beginning of the list.
- remove
- Remove a node from the list.
- pop
- Remove and return the last node in the list.
- popFirst
- Remove and return the first node in the list.
- len
- Iterate over all nodes, returning the count.
Source
Implementation
pub fn remove(list: *DoublyLinkedList, node: *Node) void {
if (node.prev) |prev_node| {
// Intermediate node.
prev_node.next = node.next;
} else {
// First element of the list.
list.first = node.next;
}
if (node.next) |next_node| {
// Intermediate node.
next_node.prev = node.prev;
} else {
// Last element of the list.
list.last = node.prev;
}
}