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

items: T[]
front: number = 0
back: number
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, undefined>)

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

Type declaration

    • (): Iterator<T, any, undefined>
    • iterate over the items in this deque, starting from the rear-most item, and ending at the front-most item

      Returns Iterator<T, any, undefined>

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

  • provide an index with relative to this.back + 1, and get the appropriate resolved index i that can be used to retrieve this.items[i].
    example: this.items[this.resolveIndex(0)] === "rear most element of the deque" example: this.items[this.resolveIndex(5)] === "fifth element ahead of the rear of the deque"

    Parameters

    • index: number

    Returns number

  • 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

Generated using TypeDoc