Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Priority queue

 
amarkirt saroay
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain me the output for priority queue?
I am not able get why the first output gives result in sorted order? It should display numbers in insertion order(1,5,3,7,6,9,8).

Please explain !


 
ramesh maredu
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please refer java doc for priority queue.

"Priority queue orders elements according to an order specified at construction time, which is specified either according to their natural order (see Comparable), or according to a Comparator".
[ July 22, 2008: Message edited by: ramesh maredu ]
 
Raphael Rabadan
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Priority Queue when we not use a Comparator uses the natural order, by natuaral order it means the Comparable the class implements, so Integer implements his comparable, and it is:



So the result is ok, take a look on this commented code:


I hope it helps.

Kind Regards,
Raphael Rabadan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic