mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-28 21:02:56 +08:00
build
This commit is contained in:
@ -220,7 +220,9 @@ comments: true
|
||||
|
||||
/* 交換元素 */
|
||||
private fun swap(i: Int, j: Int) {
|
||||
maxHeap[i] = maxHeap[j].also { maxHeap[j] = maxHeap[i] }
|
||||
val temp = maxHeap[i]
|
||||
maxHeap[i] = maxHeap[j]
|
||||
maxHeap[j] = temp
|
||||
}
|
||||
|
||||
/* 獲取堆積大小 */
|
||||
|
@ -650,7 +650,7 @@ comments: true
|
||||
|
||||
/* 獲取父節點的索引 */
|
||||
int parent(MaxHeap *maxHeap, int i) {
|
||||
return (i - 1) / 2;
|
||||
return (i - 1) / 2; // 向下取整
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user