The node type, extends SinglyLinkedListNode.
The first node in the list, or null if empty.
The number of nodes in the list.
The last node in the list, or null if empty.
Returns an iterator for traversing the list.
Optionalreversed: boolean = falseIf true, the iterator will traverse the list in reverse order.
An iterator yielding nodes in the specified order.
const list = new SinglyLinkedList();
// Add nodes to the list
list.pushNode(new SinglyLinkedListNode());
list.pushNode(new SinglyLinkedListNode());
// Forward iteration
for (const node of list) {
console.log(node);
}
// Reverse iteration
for (const node of list[Symbol.iterator](true)) {
console.log(node);
}
Retrieves the node at the specified index.
The zero-based index of the node to retrieve.
The node at the specified index, or undefined if the index is out of bounds.
Removes and returns the last node of the list.
The removed node, or undefined if the list was empty.
Removes and returns the first node of the list.
The removed node, or undefined if the list was empty.
Concrete implementation of a singly linked list.
Key characteristics:
Performance:
O(1)O(n)O(n)O(n)time and spaceO(n)Example