What will happen if you run this code?
public class PriorityQueueDemo {
public static void main(String[] args) {
Queue<Person> queue = new PriorityQueue();
queue.add(new Person(90);
queue.add(new Person(85));
queue.add(new Person(95);
queue.add(null);
System.out.println(queue.poll().getMathScore());
System.out.println(queue.poll().getMathScore());
System.out.println(queue.poll().getMathScore());
}
}
class Person {
private int mathScore;
public Person(int mathScore) {
this.mathScore = mathScore;
}
// getter and setter
}
class PersonComparator implements Comparator<Person> {
@Override
public int compare(Person p1, Person p2) {
return (p1.getMathScore() > p2.getMathScore()) ? -1 :
((p1.getMathScore() == p2.getMathScore()) ? 0 : 1);
}
}