Class LinkList<T>

Type Parameters

  • T

Hierarchy

Accessors

  • get length(): number
  • Returns

    The size of the container.

    Example

    const container = new Vector([1, 2]);
    console.log(container.length); // 2

    Returns number

Methods

  • Description

    Insert several elements after the specified position.

    Returns

    The size of container after inserting.

    Example

    const container = new Vector([1, 2, 3]);
    container.insert(1, 4); // [1, 4, 2, 3]
    container.insert(1, 5, 3); // [1, 5, 5, 5, 4, 2, 3]

    Parameters

    • pos: number

      The position you want to insert.

    • element: T

      The element you want to insert.

    • num: number = 1

      The number of elements you want to insert (default 1).

    Returns number

  • Description

    Sort the container.

    Returns

    The container's self.

    Example

    const container = new Vector([3, 1, 10]);
    container.sort(); // [1, 10, 3]
    container.sort((x, y) => x - y); // [1, 3, 10]

    Parameters

    • Optional cmp: ((x: T, y: T) => number)

      Comparison function to sort.

        • (x: T, y: T): number
        • Parameters

          • x: T
          • y: T

          Returns number

    Returns LinkList<T>

  • Description

    Merges two sorted lists.

    Returns

    The size of list after merging.

    Example

    const linkA = new LinkList([1, 3, 5]);
    const linkB = new LinkList([2, 4, 6]);
    linkA.merge(linkB); // [1, 2, 3, 4, 5];

    Parameters

    • list: LinkList<T>

      The other list you want to merge (must be sorted).

    Returns number

  • Description

    Iterate over all elements in the container.

    Example

    container.forEach((element, index) => console.log(element, index));
    

    Parameters

    • callback: ((element: T, index: number, list: LinkList<T>) => void)

      Callback function like Array.forEach.

        • (element: T, index: number, list: LinkList<T>): void
        • Parameters

          • element: T
          • index: number
          • list: LinkList<T>

          Returns void

    Returns void

Constructors

Generated using TypeDoc