Class Deque<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

    Push the element to the front.

    Returns

    The size of queue after pushing.

    Parameters

    • element: T

      The element you want to push.

    Returns number

  • 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

    Remove all elements after the specified position (excluding the specified position).

    Returns

    The size of the container after cutting.

    Example

    deque.cut(1); // Then deque's size will be 2. deque -> [0, 1]
    

    Parameters

    • pos: number

      The previous position of the first removed element.

    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 Deque<T>

  • Description

    Iterate over all elements in the container.

    Example

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

    Parameters

    • callback: ((element: T, index: number, deque: Deque<T>) => void)

      Callback function like Array.forEach.

        • (element: T, index: number, deque: Deque<T>): void
        • Parameters

          • element: T
          • index: number
          • deque: Deque<T>

          Returns void

    Returns void

Constructors

Generated using TypeDoc