Skip to content
On this page

BinaryHeap<T>

A Binary Heap is a specialized tree-based data structure which is essentially an almost complete tree that satisfies the Binary Heap property

Usage

typescript
import { BinaryHeap } from  '@algoasaurujs/tsds';

// instantiate new BinaryHeap

const queue = new BinaryHeap();

Constructors

OverloadDescription
new BinaryHeap(initialValue: T[], comparator: CompareFn<T>): BinaryHeap<T>Creates a BinaryHeap collection.

Properties

NameDescription
sizeGets the number of elements contained in the BinaryHeap<T>.

Methods

NameDescription
clear(): voidClears BinaryHeap<T>.
isEmpty(): booleanChecks if the BinaryHeap<T> is empty
peek(): TReturns the root node in the BinaryHeap
pop(): TRemoves and returns the root node in the BinaryHeap
push(value: T): voidInserts a new value into the BinaryHeap