File tree Expand file tree Collapse file tree 3 files changed +8
-5
lines changed
src/main/java/grey/algorithm/code11_heap Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Original file line number Diff line number Diff line change 4
4
// O(n)的时间复杂度完成堆化
5
5
// 笔记:https://www.cnblogs.com/greyzeng/p/16933830.html
6
6
// 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 {
8
11
public void heapify (int [] a ) {
9
12
for (int index = a .length - 1 ; index >= 0 ; index --) {
10
13
int i = index ;
Original file line number Diff line number Diff line change 23
23
// 父节点 i / 2 即:i >> 1
24
24
// 大根堆:完全二叉树中,每棵树的最大值都是头节点的值
25
25
// heapify和heapInsert都是logN级别的复杂度,因为N个节点的二叉树高度是logN
26
- public class Code_0011_MaxHeap {
26
+ public class Code_0002_MaxHeap {
27
27
private final int [] heap ;
28
28
private int heapSize ;
29
29
30
- public Code_0011_MaxHeap (int limit ) {
30
+ public Code_0002_MaxHeap (int limit ) {
31
31
heap = new int [limit ];
32
32
heapSize = 0 ;
33
33
}
@@ -102,7 +102,7 @@ public static void testHeap() {
102
102
System .out .println ("test start" );
103
103
for (int i = 0 ; i < testTimes ; i ++) {
104
104
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 );
106
106
PriorityQueue <Integer > test = new PriorityQueue <>((o1 , o2 ) -> o2 - o1 );
107
107
int curOpTimes = (int ) (Math .random () * limit );
108
108
for (int j = 0 ; j < curOpTimes ; j ++) {
Original file line number Diff line number Diff line change 11
11
// 堆排序额外空间复杂度O(1)
12
12
// 测评:https://www.lintcode.com/problem/464
13
13
//测评链接:https://www.luogu.com.cn/problem/P1177
14
- public class Code_0011_Luogu_P1177_HeapSort {
14
+ public class Code_0003_Luogu_P1177_HeapSort {
15
15
public static int MAXN = 100001 ;
16
16
public static int [] arr = new int [MAXN ];
17
17
public static int n ;
You can’t perform that action at this time.
0 commit comments