mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Polish the chapter
introduction, computational complexity.
This commit is contained in:
@ -70,7 +70,7 @@ class MaxHeap {
|
||||
while (true) {
|
||||
// 获取节点 i 的父节点
|
||||
const p = this.#parent(i);
|
||||
// 当“越过根节点”或“节点无需修复”时,结束堆化
|
||||
// 当“越过根节点”或“节点无须修复”时,结束堆化
|
||||
if (p < 0 || this.#maxHeap[i] <= this.#maxHeap[p]) break;
|
||||
// 交换两节点
|
||||
this.#swap(i, p);
|
||||
@ -102,7 +102,7 @@ class MaxHeap {
|
||||
let ma = i;
|
||||
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 越界,则无需继续堆化,跳出
|
||||
// 若节点 i 最大或索引 l, r 越界,则无须继续堆化,跳出
|
||||
if (ma === i) break;
|
||||
// 交换两节点
|
||||
this.#swap(i, ma);
|
||||
|
||||
Reference in New Issue
Block a user