This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@datastructures-js/queue) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
// empty queueconst queue =newQueue();// from an arrayconst queue =newQueue([1,2,3]);
using ".fromArray"
// empty queueconst queue = Queue.fromArray([]);// with elementsconst list =[10,3,8,40,1];const queue = Queue.fromArray(list);// If the list should not be mutated, use a copy of it.const queue = Queue.fromArray(list.slice());
.enqueue(element)
adds an element at the back of the queue.
params
name
type
element
any
runtime
O(1)
Example
queue.enqueue(10);
queue.enqueue(20);
.front()
peeks on the front element of the queue.
return
any
runtime
O(1)
Example
console.log(queue.front());// 10
.back()
peeks on the back element in the queue.
return
any
runtime
O(1)
Example
console.log(queue.back());// 20
.dequeue()
dequeue the front element in the queue. It does not use .shift() to dequeue an element. Instead, it uses a pointer to get the front element and only remove elements when reaching half size of the queue.