-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeapMe.java
More file actions
39 lines (37 loc) · 957 Bytes
/
HeapMe.java
File metadata and controls
39 lines (37 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.PriorityQueue;
import java.util.Queue;
// import java.util.Comparator;
import java.util.Random;
class HeapMe {
void init_heap(){
//
// Queue<Integer> q = new PriorityQueue<>(); // is work, ascending small2big
///
// Queue<Integer> q = new PriorityQueue<>(10, new Comparator<Integer>(){
// public int compare(Integer i1, Integer i2){
// return -(i1-i2);
// }
// });
//
PriorityQueue<Integer> q = new PriorityQueue<>((a, b)->{return a-b;});
System.out.println(q.peek());
Random r = new Random();
for(int i = 0; i < 11; i++){
int e = r.nextInt(100);
q.add(new Integer(e));
System.out.print(e);
System.out.print(" ");
}
System.out.println("");
System.out.println(q.peek());
for (int i = 0; i < 11 ; i++) {
Integer t = q.poll();
System.out.print(t.intValue());
System.out.print(" ");
}
}
public static void main(String[] args) {
HeapMe t = new HeapMe();
t.init_heap();
}
}