Queue constructor
initial data as array
Queue iterator for iteration across all nodes
Complexity: O(n)
Clear all values in Queue
Complexity: O(1)
Take head value from Queue
Complexity: O(1)
Add new value to Queue tail
Complexity: O(1)
Determines whether a value is in the Queue
Complexity: O(n)
Check value in Queue head without removing it
Complexity: O(1)
Export Queue to array
Complexity: O(n)
Queue (FIFO - first-in-first-out)
In computer science, 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 removal from the other end of the sequence. By convention, the end of the sequence at which elements are added is called the back or rear of the queue and the end at which elements are removed is called the head or front of the queue, analogously to the words used when people line up to wait for goods or services. 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. Other operations may also be allowed, often including a peek or front operation that returns the value of the next element to be dequeued without dequeuing it.
source: dev.to
Complexity
O(n)
O(n)
O(n)
O(n)
O(1)
O(1)
O(1)
O(1)
O(n)
O(n)
Reference
import { Queue } from '@pencroff/ts-algorithms/dist/structure/linked'; const q = new Queue([1, 2, 3])
Queue based on LinkedList