Format the Java codes with the Reat Hat extension.

This commit is contained in:
krahets
2023-04-14 00:12:10 +08:00
parent 7273ee24e8
commit f8513455b5
39 changed files with 195 additions and 205 deletions

View File

@ -41,9 +41,9 @@ class MaxHeap {
/* 交换元素 */
private void swap(int i, int j) {
int a = maxHeap.get(i),
b = maxHeap.get(j),
tmp = a;
int a = maxHeap.get(i);
int b = maxHeap.get(j);
int tmp = a;
maxHeap.set(i, b);
maxHeap.set(j, tmp);
}
@ -111,7 +111,8 @@ class MaxHeap {
if (r < size() && maxHeap.get(r) > maxHeap.get(ma))
ma = r;
// 若节点 i 最大或索引 l, r 越界,则无需继续堆化,跳出
if (ma == i) break;
if (ma == i)
break;
// 交换两节点
swap(i, ma);
// 循环向下堆化
@ -127,7 +128,6 @@ class MaxHeap {
}
}
public class my_heap {
public static void main(String[] args) {
/* 初始化大顶堆 */