Untitled

mail@pastecode.io avatar
unknown
typescript
7 months ago
399 B
1
Indexable
Never
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;
    }
}
Leave a Comment