posted 16 years ago
Hi,
Good Reason to be confused. Priority queue is implemented as Heap data structure. I do not know the exact details of the implementation. But with a min heap structure only one thing is assured, root has the minimum.
So after you poll the order you get 1, 2, 3, 4, 5 is pure coincidence. It could have been in any order with 1 as the root (first element).
Still confusing
1. read about heaps
2. Read how heaps are impemented in a queue
3. Look at priorityqueue fixup method.
0 will be polled out.