This commit is contained in:
krahets
2024-04-13 21:17:44 +08:00
parent 9332a91e26
commit 6afa70e7bc
55 changed files with 334 additions and 182 deletions

View File

@ -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
}
/* 获取堆大小 */

View File

@ -650,7 +650,7 @@ comments: true
/* 获取父节点的索引 */
int parent(MaxHeap *maxHeap, int i) {
return (i - 1) / 2;
return (i - 1) / 2; // 向下取整
}
```