A priority queue is a data structure with these operations:
||Creates a priority queue|
||Inserts a new value in the queue|
||Returns the number of elements in the queue|
||Returns the smallest item in the queue and leaves the queue unchanged|
||Returns the smallest item in the queue and removes it from the queue|
||Removes all values from the queue|
You cannot access the data in any other way: you must dequeue or peek.
Provides an O(log n) approach to priority queue insertions and removals. I forked this from the CoffeeScript js-priority-queue library so that I could write it in TypeScript. I've removed the array- and BHeap-based strategies as they were not recommended for use anyway.
npm install ts-priority-queue
Then write code like this:
;queue.queue5;queue.queue3;queue.queue2;; // returns 5
How exactly will these elements be ordered? Let's use the
This is the argument we would pass to
You can also pass initial values, in any order. With lots of values, it's faster to load them all at once than one at a time.
|Create||O(n lg n)|
Public Domain. Do with it what you will.