Skip to content
On this page

Queue<T>

Represents a first-in, first-out collection of objects.

A queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence. By convention, the end of the sequence at which elements are added is called the back, tail, or rear of the queue, and the end at which elements are removed is called the head or front of the queue.

The operation of adding an element to the rear of the queue is known as enqueue, and the operation of removing an element from the front is known as dequeue.

Usage

typescript
import { Queue } from  '@algoasaurujs/tsds';

// instantiate new Queue

const queue = new Queue();

Constructors

OverloadDescription
new Queue(): Queue<T>

Properties

NameDescription
lengthGets the number of elements contained in the Queue<T>.

Methods

NameDescription
clear(): voidRemoves all objects from the Queue<T>.
dequeue(): TRemoves and returns the object at the beginning of the Queue<T>.
enqueue(value: T): voidAdds an object to the end of the Queue<T>.
includes(o: T): booleanThis implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.
isEmpty(): booleanThis implementation returns length === 0.
iterator(): IterableIterator<T>
peek(): TReturns the object at the beginning of the Queue<T> without removing it.
toArray(): T[]This implementation returns an array containing all the elements returned by this collection's iterator, in the same order, stored in consecutive elements of the array, starting with index 0. The length of the returned array is equal to the number of elements returned by the iterator, even if the size of this collection changes during iteration, as might happen if the collection permits concurrent modification during iteration. The length property is called only as an optimization hint; the correct result is returned even if the iterator returns a different number of elements.