MCPcopy Create free account
hub / github.com/course-dasheng/fe-algorithm / shiftUp

Method shiftUp

interview/heap.js:16–22  ·  view source on GitHub ↗
(k)

Source from the content-addressed store, hash-verified

14 this.shiftUp(this.arr.length-1)
15 }
16 shiftUp(k){
17 let {arr,compare,parent} = this
18 while(k>1 && compare(arr[k],arr[parent(k)])){
19 this.swap(parent(k),k)
20 k = parent(k)
21 }
22 }
23 pop(){
24 // 弹出堆顶
25 if(this.arr.length==1) return null

Callers 1

pushMethod · 0.95

Calls 1

swapMethod · 0.95

Tested by

no test coverage detected