Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Priority queue

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !


 
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic