1 public class TestPriorityQueue {
2 public static void main(String[] args) {
3 Patient patient1 = new Patient("Jamal", 2);
4 Patient patient2 = new Patient("Chandra", 1);
5 Patient patient3 = new Patient("Tim", 5);
6 Patient patient4 = new Patient("Cindy", 7);
7
8 MyPriorityQueue<Patient> priorityQueue
9 = new MyPriorityQueue<>();
10 priorityQueue.enqueue(patient1);
11 priorityQueue.enqueue(patient2);
12 priorityQueue.enqueue(patient3);
13 priorityQueue.enqueue(patient4);
14
15 while (priorityQueue.getSize() > 0)
16 System.out.print(priorityQueue.dequeue() + " ");
17 }
18
19 static class Patient implements Comparable<Patient> {
20 private String name;
21 private int priority;
22
23 public Patient(String name, int priority) {
24 this.name = name;
25 this.priority = priority;
26 }
27
28 @Override
29 public String toString() {
30 return name + "(priority:" + priority + ")";
31 }
32
33 @Override
34 public int compareTo(Patient o) {
35 return this.priority - o.priority;
36 }
37 }
38 }