for (Event e : pq)
doesn't iterate in the priority order.
while(!pq.isEmpty()){ Event e = pq.poll(); }
This works but empties the queue.
From the Javadocs
The Iterator provided in method iterator() is not guaranteed to traverse the elements of the PriorityQueue in any particular order. If you need ordered traversal, consider using Arrays.sort(pq.toArray()).
iterator()
Arrays.sort(pq.toArray())
There are probably other equivalent mechanisms.
2.1m questions
2.1m answers
60 comments
57.0k users