a double-ended circular queue, similar to python's collection.deque

Type Parameters

  • T

Constructors

  • a double-ended circular queue, similar to python's collection.deque

    Type Parameters

    • T

    Parameters

    • length: number

      maximum length of the queue.
      pushing more items than the length will remove the items from the opposite side, so as to maintain the size

    Returns Deque<T>

Properties

count: number = 0
length: number

maximum length of the queue.
pushing more items than the length will remove the items from the opposite side, so as to maintain the size

[iterator]: (() => Iterator<T, any, any>)

iterate over the items in this deque, starting from the rear-most item, and ending at the front-most item

Methods

  • rotates the deque steps number of positions to the right.
    if steps is negative, then it will rotate in the left direction.
    when the deque is not empty, rotating with step = 1 is equivalent to this.pushBack(this.popFront())

    Parameters

    • steps: number

    Returns void

  • returns the item at the specified index.

    Parameters

    • index: number

      The index of the item to retrieve, relative to the rear-most element

    Returns undefined | T

    The item at the specified index, or undefined if the index is out of range

  • inserts an item at the specified index, shifting all items ahead of it one position to the front.
    if the deque is full, it removes the front item before adding the new item.

    Parameters

    • index: number
    • item: T

    Returns void