Class Queue<T>

Type Parameters

  • T = any

Hierarchy

  • Queue

Constructors

  • The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.

    Type Parameters

    • T = any

    Parameters

    • Optional elements: T[]

      The elements parameter is an optional array of elements of type T. If provided, it will be used to initialize the _nodes property of the class. If not provided, the _nodes property will be initialized as an empty array.

    Returns Queue<T>

Properties

_nodes: T[]
_offset: number

Accessors

  • get size(): number
  • The size function returns the number of elements in an array.

    Returns number

    The size of the array, which is the difference between the length of the array and the offset.

Methods

  • The clone() function returns a new Queue object with the same elements as the original Queue.

    Returns Queue<T>

    The clone() method is returning a new instance of the Queue class.

  • The dequeue function removes and returns the first element from a queue, or returns null if the queue is empty.

    Returns undefined | T

    The method is returning a value of type T or null.

  • The enqueue function adds a value to the end of a queue.

    Parameters

    • value: T

      The value parameter represents the value that you want to add to the queue.

    Returns void

  • The function checks if a data structure is empty by comparing its size to zero.

    Returns boolean

    A boolean value indicating whether the size of the object is 0 or not.

  • The peek function returns the first element of the array _nodes if it exists, otherwise it returns null.

    Returns undefined | T

    The peek() method returns the first element of the data structure, represented by the _nodes array at the _offset index. If the data structure is empty (size is 0), it returns null.

  • The peekLast function returns the last element in an array-like data structure, or null if the structure is empty.

    Returns undefined | T

    The method peekLast() returns the last element of the _nodes array if the array is not empty. If the array is empty, it returns null.

  • The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.

    Parameters

    • element: T

      The element parameter represents the element that you want to add to the queue.

    Returns Queue<T>

    The add method is returning a Queue<T> object.

  • The shift function removes and returns the first element in the queue, and adjusts the internal data structure if necessary to optimize performance.

    Returns undefined | T

    The function shift() returns either the first element in the queue or null if the queue is empty.

  • The toArray() function returns an array of elements from the current offset to the end of the _nodes array.

    Returns T[]

    An array of type T is being returned.

  • The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.

    Type Parameters

    • T

    Parameters

    • elements: T[]

      The "elements" parameter is an array of elements of type T.

    Returns Queue<T>

    The method is returning a new instance of the Queue class, initialized with the elements from the input array.

    Static

Generated using TypeDoc