-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriorityQueueDemo.java
More file actions
40 lines (35 loc) · 1.1 KB
/
PriorityQueueDemo.java
File metadata and controls
40 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
/**
Author: Rajin Santos Gajadhar
Student ID: 239479650
Final Exam: Question 11
Any and all work in this file is my own.
*/
import java.util.PriorityQueue;
public class PriorityQueueDemo {
public static void main(String[] args) {
// Test Case 1
PriorityQueue<String> fruits1 = new PriorityQueue<>();
processQueue(fruits1, "Apple");
processQueue(fruits1, "Banana");
processQueue(fruits1, "Cherry");
fruits1.remove("Banana");
System.out.println();
printQueue(fruits1);
// Test Case 2
PriorityQueue<String> fruits2 = new PriorityQueue<>();
processQueue(fruits2, "Orange");
processQueue(fruits2, "Pear");
processQueue(fruits2, "Grape");
fruits2.remove("Pear");
System.out.println();
printQueue(fruits2);
}
private static void processQueue(PriorityQueue<String> queue, String element) {
queue.add(element);
}
private static void printQueue(PriorityQueue<String> queue) {
for (String element : queue) {
System.out.println(element);
}
}
}