C
Queue
v0.0.8testedRepresents a queue data structure (FIFO) backed by a Deque
Signature
ts
class Queue<T> implements QueueLike<T>Type Parameters
TProperties
| Property | Type | Description |
|---|---|---|
lengthreadonly | number | Gets the number of elements in the queue |
isEmptyreadonly | boolean | Checks if the queue is empty |
isFullreadonly | boolean | Checks if the queue is full |
Methods
enqueueAdds an element to the back of the queue
ts
enqueue(element: T)| Parameter | Type | Description |
|---|---|---|
element | T | The element to enqueue |
Returns
thisdequeueRemoves and returns the front element of the queue
ts
dequeue()Returns
T | undefinedThe front element, or undefined if the queue is emptypeekReturns the front element without removing it
ts
peek()Returns
T | undefinedThe front element, or undefined if the queue is emptyclearClears the queue
ts
clear()Returns
thistoArrayConverts the queue to an array in FIFO order
ts
toArray()Returns
T[]toStringReturns a string representation of the queue
ts
toString()Returns
string[Symbol.iterator]Returns an iterator for the queue
ts
[Symbol.iterator]()Returns
IterableIterator<T>[Symbol.asyncIterator]Returns an async iterator for the queue
ts
async* [Symbol.asyncIterator]()Returns
AsyncGenerator<Awaited<T>, void, unknown>