-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathPriorityQueueDemo.java
More file actions
34 lines (32 loc) · 844 Bytes
/
PriorityQueueDemo.java
File metadata and controls
34 lines (32 loc) · 844 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
package SummerTrainingGFG.Heap;
import java.util.Collections;
import java.util.PriorityQueue;
/**
* @author Vishal Singh
* 16-01-2021
*/
public class PriorityQueueDemo {
/*
* By defaul it is Min heap*/
public static void main(String[] args) {
/*
* Min Heap*/
PriorityQueue<Integer> pq = new PriorityQueue<>();
pq.add(10);
pq.add(1010);
pq.add(110);
pq.add(0);
System.out.println(pq);
System.out.println(pq.poll());
System.out.println(pq.peek());
/*
* Max Heap*/
PriorityQueue<Integer> max = new PriorityQueue<>(Collections.reverseOrder());
max.add(10);
max.add(100);
max.add(1);
System.out.println(max);
System.out.println(max.poll());
System.out.println(max.peek());
}
}