This commit is contained in:
krahets
2023-08-04 05:24:49 +08:00
parent c4046ca688
commit fafdebb75c
27 changed files with 972 additions and 536 deletions
+2 -2
View File
@@ -1256,7 +1256,7 @@ comments: true
if (l < this.size() && this.#maxHeap[l] > this.#maxHeap[ma]) ma = l;
if (r < this.size() && this.#maxHeap[r] > this.#maxHeap[ma]) ma = r;
// 若节点 i 最大或索引 l, r 越界,则无需继续堆化,跳出
if (ma == i) break;
if (ma === i) break;
// 交换两节点
this.#swap(i, ma);
// 循环向下堆化
@@ -1292,7 +1292,7 @@ comments: true
if (l < this.size() && this.maxHeap[l] > this.maxHeap[ma]) ma = l;
if (r < this.size() && this.maxHeap[r] > this.maxHeap[ma]) ma = r;
// 若节点 i 最大或索引 l, r 越界,则无需继续堆化,跳出
if (ma == i) break;
if (ma === i) break;
// 交换两节点
this.swap(i, ma);
// 循环向下堆化