A ring queue is a queue that has a fixed capacity. When the queue is full, the oldest element is removed to make room for the new element. Reading from a ring queue will return the oldest element and effectively remove it from the queue.

Type Parameters

  • E

Hierarchy

  • RingQueue

Implements

Constructors

Properties

Methods

Constructors

Properties

elements: E[]
head: number
tail: number

Methods

  • Adds an element to the queue.

    Parameters

    • element: E

      the element to add

    Returns void

  • Calls the given function for each element in the queue.

    Parameters

    • fn: ((element) => unknown)

      the function to call

        • (element): unknown
        • Parameters

          • element: E

          Returns unknown

    Returns void

  • Whether the queue is empty.

    Returns boolean

    true if the queue is empty, false otherwise

  • Number of elements in the queue.

    Returns number

    the number of elements in the queue

  • Returns the next element in the queue without removing it.

    Returns undefined | E

    the next element in the queue, or undefined if the queue is empty

  • Removes and returns the next element in the queue.

    Returns undefined | E

    the next element in the queue, or undefined if the queue is empty

Generated using TypeDoc