-
Notifications
You must be signed in to change notification settings - Fork 0
/
QHeap1.java
32 lines (29 loc) · 871 Bytes
/
QHeap1.java
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
import java.util.PriorityQueue;
import java.util.Scanner;
/**
* Created by Bryan Tamada on 1/2/16.
*/
public class QHeap1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PriorityQueue<Integer> minHeap = new PriorityQueue<>();
int Q = sc.nextInt(); // the number of queries
int queryType = 0;
int element = 0;
while(Q-->0) {
queryType = sc.nextInt();
switch(queryType){
case 1:
element = sc.nextInt();
minHeap.add(element);
break;
case 2:
element = sc.nextInt();
minHeap.remove(element);
break;
case 3:
System.out.println(minHeap.peek());
}
}
}
}