dns-suite.js/node_modules/binaryheap/example.js

16 lines
296 B
JavaScript
Raw Normal View History

2017-01-14 02:04:27 +00:00
var BinaryHeap = require('./binaryheap');
var heap = new BinaryHeap();
var a = [6, 5, 3, 1, 8, 7, 2, 4];
a.forEach(function (k) {
heap.insert({ value: k }, k);
});
heap.print(process.stdout);
while (heap.length) {
console.log('popping', heap.pop().value);
heap.print(process.stdout);
}