Trouble with extracting maximum value from Max Heap using JavaScript

19 Views Asked by At

i tried to put this.val[swap] = this.val[index] because it is same as index

what the logic

    sink(){
        let index= 0;
        const length = this.val.length; // total length
        const element = this.val[index]
    
            if(swap === null) break;
            this.val[index] = this.val[swap];
            this.val[swap] = element;
            index= swap;
        }
    }
}
0

There are 0 best solutions below