elements data type: any type.
const pQueueFn = require('@datastructures-js/priority-queue');
const pQueue = pQueueFn();.enqueue(element, priority)
adds an element with priority (number) to the back of the queue.
pQueue.enqueue('patient 1', 2); // lower priority
pQueue.enqueue('patient 2', 1); // higher priority.front()
returns the front element in queue.
console.log(pQueue.front()); // patient 1.back()
returns the back element in the queue.
console.log(pQueue.back()); // patient 3.dequeue()
dequeues the highest priority element from the queue.
console.log(pQueue.dequeue()); // patient 2
console.log(pQueue.front()); // patient 1.isEmpty()
checks if the queue is empty.
console.log(pQueue.isEmpty()); // false.length()
returns the length of the queue.
console.log(pQueue.length()); // 1.toArray()
converts the queue to an array from highest prority element to lowest
pQueue.enqueue('patient 3', 5);
pQueue.enqueue('patient 4', 1);
console.log(pQueue.toArray()); // ['patient 4', 'patient 1', 'patient 5'].clear()
clears the queue
pQueue.clear();
console.log(pQueue.length()); // 0grunt build
The MIT License. Full License is here