-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLearnPriorityQueue.java
More file actions
38 lines (32 loc) · 978 Bytes
/
LearnPriorityQueue.java
File metadata and controls
38 lines (32 loc) · 978 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
import java.util.*;
public class LearnPriorityQueue {
public static void main(String args[]){
Queue<Integer> pq = new PriorityQueue<>();
pq.offer(40);
pq.offer(20);
pq.offer(50);
pq.offer(30);
pq.offer(10);
System.out.println(pq);
System.out.println(pq.peek());
pq.poll();
System.out.println(pq);
Queue<String> pqs = new PriorityQueue<>();
pqs.offer("Tejas");
pqs.offer("Ketan");
pqs.offer("Prathmesh");
pqs.offer("Abhi");
pqs.offer("Aabhi");
System.out.println(pqs);
Queue<Integer> pqr = new PriorityQueue<>(Comparator.reverseOrder());
pqr.offer(40);
pqr.offer(20);
pqr.offer(50);
pqr.offer(30);
pqr.offer(10);
System.out.println(pqr);
System.out.println(pqr.peek());
pqr.poll();
System.out.println(pqr);
}
}