• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Modifying PriorityQueue keys while in queue

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it acceptable to modify the keys of PriorityQueue elements while they are in the queue? That is, can I do something like this:



I expect to get 2, 0, 4, 3, 1 when I run this, but I actually get 0, 2, 4, 3, 1. This leads me to believe that elements only get sorted when they are inserted into the queue, and not when they're polled. Am I right? If so, is there some other structure I should be using instead for this? To the best of my knowledge, Priority Queues should allow for this...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic