DoublyLinkedList

Positional linked list with elements linked in both directions from head to tail and vice versa.

Generic types (only for TS):

T - Type of elements stored in the list.

new DoublyLinkedList()

/**
 * Creates an instance of DoublyLinkedList.
 *
 * @param elements Array of elements to create the new linked list with.
 */
constructor(elements: T[] = [])

Creating a DoublyLinkedList with elements 1->2->3:

new DoublyLinkedList([1, 2, 3]);

length

/**
 * Number of elements in the list.
 *
 * @readonly
 */
get length(): number

Adding element increases list length:

addAfter()

Adding element after the specified position:

addBefore()

Adding element before the specified position:

addFirst()

Adding element at the front of a list:

addLast()

Adding element at the back of a list:

clear()

Deep clearing:

Fast clearing:

delete()

Deleting element at the specified position:

getAfter()

Getting position after the specified:

getBefore()

Getting position before the specified:

getFirst()

Getting position of the first element:

getLast()

Getting position of the last element:

circle-info

getLast() and getFirst() return positions of the same element if list has only one element. These positions won't be the same object however.

isEmpty()

Adding element makes list not empty:

removeFirst()

Removing element deprecates its position:

removeLast()

Removing element deprecates its position:

replace()

Replacing element takes effect for all positions pointing to it:

[Symbol.iterator]()

Building an array from list:

See also

Position

Last updated