Skip to content

PriorityQueue<T>

Guide: /guide/data-structures/priority-queue

Generic Types

T - type of collection elements

Methods

constructor(): PriorityQueue<T>

Creates a new PriorityQueue instance with default min-heap behavior.



isEmpty(): boolean

Returns true if the queue is empty.



enqueue(value: T, priority: number): void

Adds an element to the queue with a specific priority.

Params:
NameTypeRequiredDefaultDescription
valueT+-The data to store.
prioritynumber+-The priority level (lower value = higher priority).



dequeue(): T

Removes and returns the element with the highest priority (lowest priority number).

Throws: CollectionIsEmptyException when queue is empty



peek(): T

Returns the highest priority element without removing it.

Throws: CollectionIsEmptyException when queue is empty



clear(): void

Clears all elements from the queue.



size

Type: number

Number of elements in the queue.



MIT Licensed