The node type, extends DoublyLinkedListNode
.
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.
Optional
reversed: boolean = falseIf true
, the iterator will traverse the list in reverse order.
An iterator yielding nodes in the specified order.
const list = new DoublyLinkedList();
// Add nodes to the list
list.pushNode(new DoublyLinkedListNode());
list.pushNode(new DoublyLinkedListNode());
// 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 doubly linked list.
Key characteristics:
Performance:
O(1)
O(n)
O(min(k,n-k))
O(1)
with direct referenceExample