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(): numberAdding 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:
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
Last updated
Was this helpful?