Class Queue<T>

A queue data structure.

Type Parameters

  • T

    The type of elements held in the queue.

Hierarchy

Implements

Constructors

Properties

Accessors

Methods

Constructors

  • Creates a new queue with the specified size or elements.

    Type Parameters

    • T

    Parameters

    • size: number | T[]

      The size of the queue or an array of elements to initialize the queue with.

    Returns Queue<T>

Properties

_data: T[] = []
_head: number = 0
_tail: number = 0
size: number = 0

The number of elements in the list.

Accessors

  • get items(): readonly T[]
  • Returns an array of all elements in the queue.

    Returns readonly T[]

    An array of all elements in the queue or an empty array if the queue is empty.

Methods

  • Removes and returns the element at the front of the queue.

    Returns T

    The element at the front of the queue.

    Throws

    An error if the queue is empty.

  • Adds an element to the end of the queue.

    Parameters

    • element: T

      The element to add to the queue.

    Returns void

    Throws

    An error if the queue is full.

  • Returns the element at the front of the queue without removing it.

    Returns undefined | T

    The element at the front of the queue or undefined if the queue is empty.