posted 16 years ago
No, you're wrong.
First:
add() and offer() in a priority queue do the same.
The priority queue is ordered, but not from the sequence, you put the elements in. It is ordered by natural order of the elements.
Trap:
if you just iterate the queue, the output might be the same as the sequence of input.
The order can be seen only if you poll the elements out individually.
Second
If you want to retain the order of your array, you shouldn't use a priority queue at all. Take a linked list.
Example (change offer to add and retry):
Try it.
Yours,
Bu.
all events occur in real time