1.1.0 • Published 2 years ago

pheapjs v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago
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
*/