pheapjs
v1.1.0
Published
heap data structure in js
Downloads
8
Maintainers
Readme
const { Heap } = require('pheapjs');
const h = new Heap((a, b) => a - b);
// the compareFunc can passed by Heap constructor as argument as the pre line or as below
// h.compareFunc = (a, b) => a - b;
// offer datas
h.offer(2);
h.offer(6);
h.offer(1);
h.offer(5);
h.offer(7);
h.offer(8);
h.offer(9);
h.offer(3);
h.offer(3);
// h.setCompareFunc((a, b) => b -a);
// console.log(h._datas)
// console.log(h.peek());
// pull datas
while (h.size() > 0) {
console.log(h.pull());
}
/*
output is:
1
2
3
3
5
6
7
8
9
*/