-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathHeap.java
More file actions
43 lines (35 loc) · 1.1 KB
/
Copy pathHeap.java
File metadata and controls
43 lines (35 loc) · 1.1 KB
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
40
41
42
43
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
/**
* Created with IntelliJ IDEA.
* User: windows 7
* Date: 12/10/14
* Time: 8:40 PM
* To change this template use File | Settings | File Templates.
*/
public class Heap {
public static void main(String[] args) throws Exception {
PriorityQueue<Integer> minHeap = new PriorityQueue<Integer>();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String line;
int temp;
while (true) {
line = bufferedReader.readLine();
if (line.equals("exit")) {
break;
} else if (line.equals("print")) {
//print min element
if (minHeap.size() > 0) {
System.out.println("minimum element is " + minHeap.peek());
}
} else {
try {
temp = Integer.parseInt(line);
minHeap.add(temp);
} catch (Exception e) {
}
}
}
}
}