Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 947 Bytes

File metadata and controls

32 lines (24 loc) · 947 Bytes

Data Structure - Priority Queue

priorityQueue-file-ts priorityQueue-gzip-ts priorityQueue-brotli-ts

Description

A priority queue is a data structure that stores elements in a specific order. The user has the power to define the order of priority.

Usage

import { PriorityQueue } from 'gis-tools-ts';

// Create a priority queue that sorts numbers in ascending order
const queue = new PriorityQueue<number>([], (a, b) => a - b);

queue.push(1);
queue.push(2);

const current = queue.peek(); // 1
console.log(queue.length); // 2
let next = queue.pop(); // 1
console.log(queue.length); // 1
next = queue.pop(); // 2
console.log(queue.length); // 0