Class CircArrayQueue<T>

Circular array queue -- an implementation of the Queue ADT using a circular array along with a dynamic resizing scheme.

Implements

Type Parameters

  • T

    The type of all elements in the queue.

Hierarchy

  • CircArrayQueue

Implements

Constructors

  • Creates an empty queue.

    Type Parameters

    • T

      The type of all elements in the queue.

    Parameters

    • initCapacity: number = 2

      Initial anticipated number of elements to be stored in the queue.

    Returns CircArrayQueue<T>

Properties

#elems: T[]

The underlying array for storing queue elements of type T.

#numElems: number

Number of elements in the queue.

#startIdx: number

Position of the front element in the underlying array.

#growthFactor: number = 2

Growth factor for the underlying array.

Static

Accessors

  • get #endIdx(): number
  • Position of the one past the last queue element in the underlying array.

    Returns number

  • get capacity(): number
  • The maximum number of elements the queue can store without allocating additional memory.

    Returns number

  • get size(): number
  • Number of elements in the queue.

    Returns number

Methods

  • Grows or shrinks the underlying array by a factor of 2.

    Parameters

    • grow: boolean = true

      Grow/shrink flag.

    Returns void

  • Removes the front element from the queue if not empty.

    Returns

    true on success, false otherwise.

    Returns boolean

  • Whether the queue has no elements.

    Returns

    true if the queue is empty, false otherwise.

    Returns boolean

  • Adds an element to the end of the queue.

    Parameters

    • elem: T

      The element to be added.

    Returns void

  • Gets the element at the front of the queue if not empty.

    Returns

    The front element.

    Returns null | T

  • Iterates over all elements of this queue from the front.

    The given operation will be performed on each element iterated.

    Parameters

    • action: ((elem: T) => void)

      The operation to be performed on each element.

        • (elem: T): void
        • Parameters

          • elem: T

          Returns void

    Returns void

  • Creates a string representation of this queue.

    Elements are presented in the queue order from left to right.

    Returns

    The string representation.

    Parameters

    • separator: string = ' '

      Element separator. Defaults to a single space character.

    Returns string

Generated using TypeDoc