A priority queue is a data structure that stores elements in a specific order.
import { PriorityQueue } from 'gis-tools-ts';const queue = new PriorityQueue<number>([], (a, b) => a - b);queue.push(1);queue.push(2);const current = queue.peek(); // 1console.log(queue.length); // 2let next = queue.pop(); // 1console.log(queue.length); // 1next = queue.pop(); // 2console.log(queue.length); // 0 Copy
import { PriorityQueue } from 'gis-tools-ts';const queue = new PriorityQueue<number>([], (a, b) => a - b);queue.push(1);queue.push(2);const current = queue.peek(); // 1console.log(queue.length); // 2let next = queue.pop(); // 1console.log(queue.length); // 1next = queue.pop(); // 2console.log(queue.length); // 0
initial data
compare function
Peek at the top item without removing it
Access the top item, remove it, and return it
Push an item into the queue
the item to store
Priority Queue
Description
A priority queue is a data structure that stores elements in a specific order.
Usage