-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPriorityQueue.java
More file actions
47 lines (31 loc) · 976 Bytes
/
MPriorityQueue.java
File metadata and controls
47 lines (31 loc) · 976 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
40
41
42
43
44
45
46
47
package structure;
import java.util.*;
public class MPriorityQueue {
public static void run() {
System.out.println("\n==== Priority Queue ====\n");
/**
* Priority Queue = A FIFO data Structure that serves elements
* with the highst priorities first before elements
* with lower priority
*/
Queue<Double> queue1 = new PriorityQueue<>(Collections.reverseOrder());
queue1.offer(3.0);
queue1.offer(2.5);
queue1.offer(4.0);
queue1.offer(1.5);
queue1.offer(2.0);
while(!queue1.isEmpty()) {
System.out.println(queue1.poll());
}
System.out.println("\nPriority Queues with Strings\n");
Queue<String> queue2 = new PriorityQueue<>(Collections.reverseOrder());
queue2.offer("B");
queue2.offer("C");
queue2.offer("A");
queue2.offer("E");
queue2.offer("D");
while(!queue2.isEmpty()) {
System.out.println(queue2.poll());
}
}
}