Untitled
unknown
typescript
2 years ago
399 B
8
Indexable
class Heap {
constructor(compareFunc) {
this.compareFunc = compareFunc;
this.heap = new Array();
}
insert(val) {
this.heap.push(val);
this.heap.sort(this.compareFunc);
}
extract() {
return this.heap.shift();
}
peek() {
return this.heap[0];
}
get size() {
return this.heap.length;
}
}Editor is loading...
Leave a Comment