We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7250c4e commit 8c005c5Copy full SHA for 8c005c5
十大排序算法_Java/Heap.java
@@ -22,7 +22,8 @@ public int[] heapSort(int[] nums) {
22
// 堆调整的逻辑:父节点与子节点较大者交换,最终最大值会升到根节点
23
private void max_heapify(int[] nums, int root) {
24
int maxIndex = root;
25
- int left = root * 2, right = root * 2 + 1;
+ // 索引从0开始
26
+ int left = root * 2 + 1, right = root * 2 + 2;
27
// 如果有左孩子,且左孩子大于父节点,则将最大指针指向左孩子
28
if (left < n && nums[left] > nums[maxIndex])
29
maxIndex = left;
0 commit comments