Online Java Compiler By
JavaTpoint.com
import java.util.PriorityQueue; class Patient implements Comparable{ String name; public Patient(String name) { this.name = name; } @Override public int compareTo(Object o) { return 0; } } public class PriorityQueuePollExample3 { public static void main(String[] args) { PriorityQueue
Pqueue = new PriorityQueue
(); Patient p1 = new Patient("Arnavi"); Patient p2 = new Patient("Himani"); Patient p3 = new Patient("Sarita"); Pqueue.add(p1); Pqueue.add(p2); Pqueue.add(p3); System.out.println(Pqueue.poll().name+" can visit the doctor at first. "); System.out.println(Pqueue.poll().name+" can visit the doctor after the first patient. "); System.out.println(Pqueue.poll().name+" can visit the doctor after the second patient. "); } }
Output