Skip to content

Commit ef739c2

Browse files
committed
heap
1 parent 14d4d6c commit ef739c2

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/main/java/grey/algorithm/code11_heap/Code_0011_LintCode_0130_Heapify.java renamed to src/main/java/grey/algorithm/code11_heap/Code_0001_LintCode_0130_Heapify.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
// O(n)的时间复杂度完成堆化
55
// 笔记:https://www.cnblogs.com/greyzeng/p/16933830.html
66
// https://www.lintcode.com/problem/130/
7-
public class Code_0011_LintCode_0130_Heapify {
7+
//左孩子 2 * i + 1
8+
//右孩子 2 * i + 2
9+
//父节点 (i - 1)/ 2
10+
public class Code_0001_LintCode_0130_Heapify {
811
public void heapify(int[] a) {
912
for (int index = a.length - 1; index >= 0; index--) {
1013
int i = index;

src/main/java/grey/algorithm/code11_heap/Code_0011_MaxHeap.java renamed to src/main/java/grey/algorithm/code11_heap/Code_0002_MaxHeap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
// 父节点 i / 2 即:i >> 1
2424
// 大根堆:完全二叉树中,每棵树的最大值都是头节点的值
2525
// heapify和heapInsert都是logN级别的复杂度,因为N个节点的二叉树高度是logN
26-
public class Code_0011_MaxHeap {
26+
public class Code_0002_MaxHeap {
2727
private final int[] heap;
2828
private int heapSize;
2929

30-
public Code_0011_MaxHeap(int limit) {
30+
public Code_0002_MaxHeap(int limit) {
3131
heap = new int[limit];
3232
heapSize = 0;
3333
}
@@ -102,7 +102,7 @@ public static void testHeap() {
102102
System.out.println("test start");
103103
for (int i = 0; i < testTimes; i++) {
104104
int curLimit = (int) (Math.random() * limit) + 1;
105-
Code_0011_MaxHeap my = new Code_0011_MaxHeap(curLimit);
105+
Code_0002_MaxHeap my = new Code_0002_MaxHeap(curLimit);
106106
PriorityQueue<Integer> test = new PriorityQueue<>((o1, o2) -> o2 - o1);
107107
int curOpTimes = (int) (Math.random() * limit);
108108
for (int j = 0; j < curOpTimes; j++) {

src/main/java/grey/algorithm/code11_heap/Code_0011_Luogu_P1177_HeapSort.java renamed to src/main/java/grey/algorithm/code11_heap/Code_0003_Luogu_P1177_HeapSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// 堆排序额外空间复杂度O(1)
1212
// 测评:https://www.lintcode.com/problem/464
1313
//测评链接:https://www.luogu.com.cn/problem/P1177
14-
public class Code_0011_Luogu_P1177_HeapSort {
14+
public class Code_0003_Luogu_P1177_HeapSort {
1515
public static int MAXN = 100001;
1616
public static int[] arr = new int[MAXN];
1717
public static int n;

0 commit comments

Comments
 (0)