mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-04 19:20:52 +08:00
Polish the chapter
introduction, computational complexity.
This commit is contained in:
@@ -11,7 +11,7 @@ import java.util.*;
|
||||
|
||||
/* 大顶堆 */
|
||||
class MaxHeap {
|
||||
// 使用列表而非数组,这样无需考虑扩容问题
|
||||
// 使用列表而非数组,这样无须考虑扩容问题
|
||||
private List<Integer> maxHeap;
|
||||
|
||||
/* 构造方法,根据输入列表建堆 */
|
||||
@@ -74,7 +74,7 @@ class MaxHeap {
|
||||
while (true) {
|
||||
// 获取节点 i 的父节点
|
||||
int p = parent(i);
|
||||
// 当“越过根节点”或“节点无需修复”时,结束堆化
|
||||
// 当“越过根节点”或“节点无须修复”时,结束堆化
|
||||
if (p < 0 || maxHeap.get(i) <= maxHeap.get(p))
|
||||
break;
|
||||
// 交换两节点
|
||||
@@ -108,7 +108,7 @@ class MaxHeap {
|
||||
ma = l;
|
||||
if (r < size() && maxHeap.get(r) > maxHeap.get(ma))
|
||||
ma = r;
|
||||
// 若节点 i 最大或索引 l, r 越界,则无需继续堆化,跳出
|
||||
// 若节点 i 最大或索引 l, r 越界,则无须继续堆化,跳出
|
||||
if (ma == i)
|
||||
break;
|
||||
// 交换两节点
|
||||
|
||||
Reference in New Issue
Block a user