0

I try to write a program using a priorityQueue ADT ( the documentation is found here: http://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html ). The priorityQueue orders instances of a nested class Node which has two variables: an integer representing the weight (or the priority) and a String representing the information to be stored inside the queue.

The problem I face is to change an element's priority (i.e. its weight) without pulling the element out of the queue ( using the function remove() ) and then pushing a new one with the new priority ( using the function add() ). I would like to be able to change the integer representing the weight inside an instance of a class Node inside the queue and then the priorityQueue will reorder itself to find if there is a new Node to place at the head of the queue.

And a last thing: I don't have to use the priorityQueue ADT. If there is any other ADT that resolves this issue in a more elegant manner, be free to mention it!

I am pretty sure I'm not the first person to encounter this difficulty so I'm sorry if there is already an answer to this question anywhere on this website but I haven't found it.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Dust009
  • 315
  • 2
  • 10
  • In short, you want/need to create a priority queue using Nodes for the implementation rather than an array? Good luck with that :) – Luiggi Mendoza Jan 23 '15 at 21:15
  • As I said in my question, if there is any other ADT than the priorityQueue ADT that can achieve this goal, it's ok for me :) – Dust009 Jan 23 '15 at 23:47

0 Answers0