Class LinkedList<T>

A generic doubly-linked list.

Type Parameters

  • T

Implements

Constructors

Properties

_first: null | LinkedListNode<T> = null
_last: null | LinkedListNode<T> = null
_size: number = 0

Accessors

  • get first(): undefined | T
  • The first value in the list.

    This is undefined if the list is empty.

    Complexity

    Constant.

    Returns undefined | T

  • get last(): undefined | T
  • The last value in the list.

    This is undefined if the list is empty.

    Complexity

    Constant.

    Returns undefined | T

  • get length(): number
  • The length of the list.

    Complexity

    Constant.

    Notes

    This is equivalent to size.

    This property is deprecated.

    Returns number

Methods

  • Create an iterator over the values in the list.

    Returns IterableIterator<T>

    A new iterator starting with the first value.

    Complexity

    Constant.

  • Add a value to the beginning of the list.

    Parameters

    • value: T

      The value to add to the beginning of the list.

    Returns INode<T>

    The list node which holds the value.

    Complexity

    Constant.

  • Add a value to the end of the list.

    Parameters

    • value: T

      The value to add to the end of the list.

    Returns INode<T>

    The list node which holds the value.

    Complexity

    Constant.

  • Assign new values to the list, replacing all current values.

    Parameters

    • values: Iterable<T>

      The values to assign to the list.

      Complexity

      Linear.

    Returns void

  • Insert a value after a specific node in the list.

    Parameters

    • value: T

      The value to insert after the reference node.

    • ref: null | INode<T>

      The reference node of interest. If this is null, the value will be added to the end of the list.

    Returns INode<T>

    The list node which holds the value.

    Notes

    The reference node must be owned by the list.

    Complexity

    Constant.

  • Insert a value before a specific node in the list.

    Parameters

    • value: T

      The value to insert before the reference node.

    • ref: null | INode<T>

      The reference node of interest. If this is null, the value will be added to the beginning of the list.

    Returns INode<T>

    The list node which holds the value.

    Notes

    The reference node must be owned by the list.

    Complexity

    Constant.

  • Create an iterator over the nodes in the list.

    Returns IterableIterator<INode<T>>

    A new iterator starting with the first node.

    Complexity

    Constant.

  • Remove and return the value at the end of the list.

    Returns undefined | T

    The removed value, or undefined if the list is empty.

    Complexity

    Constant.

    Notes

    This is equivalent to removeLast.

  • Add a value to the end of the list.

    Parameters

    • value: T

      The value to add to the end of the list.

      Complexity

      Constant.

      Notes

      This is equivalent to addLast.

    Returns void

  • Remove and return the value at the beginning of the list.

    Returns undefined | T

    The removed value, or undefined if the list is empty.

    Complexity

    Constant.

  • Remove and return the value at the end of the list.

    Returns undefined | T

    The removed value, or undefined if the list is empty.

    Complexity

    Constant.

  • Remove a specific node from the list.

    Parameters

    • node: INode<T>

      The node to remove from the list.

      Complexity

      Constant.

      Notes

      The node must be owned by the list.

    Returns void

  • Create a reverse iterator over the values in the list.

    Returns IterableIterator<T>

    A new iterator starting with the last value.

    Complexity

    Constant.

  • Create a reverse iterator over the nodes in the list.

    Returns IterableIterator<INode<T>>

    A new iterator starting with the last node.

    Complexity

    Constant.

  • Add a value to the beginning of the list.

    Parameters

    • value: T

      The value to add to the beginning of the list.

      Complexity

      Constant.

      Notes

      This is equivalent to addFirst.

    Returns void

  • Remove and return the value at the beginning of the list.

    Returns undefined | T

    The removed value, or undefined if the list is empty.

    Complexity

    Constant.

    Notes

    This is equivalent to removeFirst.