JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 209252
  • Score
    100M100P100Q190662F
  • License MIT

priority queue implementation in javascript

Package Exports

  • @datastructures-js/priority-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/priority-queue) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@datastrucures-js/priority-queue

build:? npm npm npm

elements data type: any type.

Usage

const pQueueFn = require('@datastructures-js/priority-queue');
const pQueue = pQueueFn();

API

.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()); // 0

Build

grunt build

License

The MIT License. Full License is here