min-heap-typed
v2.0.0
Published
Min Heap. Javascript & Typescript Data Structure.
Downloads
2,254
Maintainers
Keywords
Readme
What
Brief
This is a standalone Min Heap data structure from the data-structure-typed collection. If you wish to access more data structures or advanced features, you can transition to directly installing the complete data-structure-typed package
How
install
npm
npm i min-heap-typed --save
yarn
yarn add min-heap-typed
snippet
TS
import {MinHeap} from 'data-structure-typed';
// /* or if you prefer */ import {MinHeap} from 'heap-typed';
const minNumHeap = new MinHeap<number>();
minNumHeap.add(1).add(6).add(2).add(0).add(5).add(9);
minNumHeap.has(1) // true
minNumHeap.has(2) // true
minNumHeap.poll() // 0
minNumHeap.poll() // 1
minNumHeap.peek() // 2
minNumHeap.has(1); // false
minNumHeap.has(2); // true
const arrFromHeap = minNumHeap.toArray();
arrFromHeap.length // 4
arrFromHeap[0] // 2
arrFromHeap[1] // 5
arrFromHeap[2] // 9
arrFromHeap[3] // 6
minNumHeap.sort() // [2, 5, 6, 9]
JS
const {MinHeap} = require('data-structure-typed');
// /* or if you prefer */ const {MinHeap} = require('heap-typed');
const minNumHeap = new MinHeap();
minNumHeap.add(1).add(6).add(2).add(0).add(5).add(9);
minNumHeap.has(1) // true
minNumHeap.has(2) // true
minNumHeap.poll() // 0
minNumHeap.poll() // 1
minNumHeap.peek() // 2
minNumHeap.has(1); // false
minNumHeap.has(2); // true
const arrFromHeap = minNumHeap.toArray();
arrFromHeap.length // 4
arrFromHeap[0] // 2
arrFromHeap[1] // 5
arrFromHeap[2] // 9
arrFromHeap[3] // 6
minNumHeap.sort() // [2, 5, 6, 9]
API docs & Examples
Examples Repository