Class LinkedList<T>

LinkedList data structure. It is a linear data structure where elements are stored in a non-contiguous manner. Each element is a separate object and contains a reference to the next and previous elements in the LinkedList. Each element is called a node and consists of a value and a reference to the next and previous nodes. The first node is called the head and the last node is called the tail.

The LinkedList class has the following methods:
  • push(value: T): void - Adds a new value to the end of the LinkedList.
  • pop(): T | null - Removes the last value from the LinkedList.
  • shift(): T | null - Removes the first value from the LinkedList.
  • unshift(value: T): void - Adds a new value to the beginning of the LinkedList.
  • get(index: number): T | null - Returns the value at the given index.
  • set(index: number, value: T): boolean - Sets the value at the given index.
  • insert(index: number, value: T): boolean - Inserts a new value at the given index.
  • remove(index: number): T | null - Removes the value at the given index.
  • indexOf(value: T): number - Returns the index of the given value.
  • toString(): string - Returns a string representation of the LinkedList.

Type Parameters

  • T

Hierarchy

  • LinkedList

Constructors

Properties

head: null | LinkedListNode<T> = null
length: number = 0
tail: null | LinkedListNode<T> = null

Methods

  • Returns the node at the given index.

    Parameters

    • index: number

      index to be searched

    Returns null | LinkedListNode<T>

    LinkedListNode | null

  • Returns the value of the node at the given index.

    Parameters

    • index: number

      index to be searched

    Returns null | T

    T | null

  • Returns the index of the given value.

    Parameters

    • value: T

      value to be searched

    Returns number

    number

  • Inserts a new value at the given index.

    Parameters

    • index: number

      index to be inserted

    • value: T

      value to be inserted

    Returns boolean

    boolean

  • Adds a new value to the end of the LinkedList.

    Parameters

    • value: T

      value to be added

    Returns void

  • Removes the value at the given index.

    Parameters

    • index: number

      index to be removed

    Returns null | T

    T | null

  • Sets the value at the given index.

    Parameters

    • index: number

      index to be set

    • value: T

      value to be set

    Returns boolean

    boolean

  • Adds a new value to the beginning of the LinkedList.

    Parameters

    • value: T

      value to be added

    Returns void

Generated using TypeDoc