a highly performant queue implementation in javascript
Package Exports
@datastructures-js/queue
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.
Readme
@datastructures-js/queue
A highly performant queue implementation in javascript.
// empty queueconst queue =newQueue();// from an arrayconst queue =newQueue([1,2,3]);
using "Queue.fromArray(array)"
Example
// 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, simply construct the queue from a copy of it.const queue = Queue.fromArray(list.slice(0));
.enqueue(element)
adds an element at the back of the queue.
params
name
type
element
object
runtime
O(1)
Example
queue.enqueue(10);
queue.enqueue(20);
.front()
peeks on the front element of the queue.
return
object
runtime
O(1)
Example
console.log(queue.front());// 10
.back()
peeks on the back element in the queue.
return
object
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.