SinglyLinkedList

Positional linked list with elements linked in one direction from head to tail.

Generic types (only for TS):

T - Type of elements stored in the list.

new SinglyLinkedList()

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

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

new SinglyLinkedList([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:

addFirst()

Adding element at the front of a list:

addLast()

Adding element at the back of a list:

clear()

Deep clearing:

Fast clearing:

getAfter()

Getting position after 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:

replace()

Replacing element takes effect for all positions pointing to it:

[Symbol.iterator]()

Building an array from list:

See also

Position

Last updated

Was this helpful?