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
| Overload | Description |
|---|---|
| new BinaryHeap(initialValue: T[], comparator: CompareFn<T>): BinaryHeap<T> | Creates a BinaryHeap collection. |
Properties
| Name | Description |
|---|---|
| size | Gets the number of elements contained in the BinaryHeap<T>. |
Methods
| Name | Description |
|---|---|
| clear(): void | Clears BinaryHeap<T>. |
| isEmpty(): boolean | Checks if the BinaryHeap<T> is empty |
| peek(): T | Returns the root node in the BinaryHeap |
| pop(): T | Removes and returns the root node in the BinaryHeap |
| push(value: T): void | Inserts a new value into the BinaryHeap |
TSDS