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

Method sinkDown

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

Source from the content-addressed store, hash-verified

29 return head
30 }
31 sinkDown(k){
32 let {arr,compare,left,right,size} = this
33 while(left(k)<=size){
34 let child = left(k)
35 if(right(k)<=size && compare(arr[right(k)],arr[child])){
36 child = right(k)
37 }
38 if(compare(arr[k],arr[child])) {
39 return
40 }
41 this.swap(k,child)
42 k = child //继续向下
43 }
44 }
45
46 peek(){
47 // 获取堆顶元素

Callers 1

popMethod · 0.95

Calls 1

swapMethod · 0.95

Tested by

no test coverage detected