Reordering elements in a PriorityQueue

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Reordering elements in a PriorityQueue

oramas martín
Hi all,

I would like to insert elements in a PriorityQueue where the value returned
by the 'lessThan' method for the same both objects can change over the time.
Just to clarify my problem, I would like to insert PriorityQueue objects in
the main PriorityQueue, so the 'lessThan' method from the main queue will
compare the top objects of the inserted priority queues.

So I would like to reorder an alement already in the queue, each time it is
detected a change in its value. AFAIK, it can not be done with the current
PriorityQueue implementation, so I have, apparently, two ways of doing it,
one can be remove the affected element and reinsert it, and the other is to
implement a reorder method. In either case I have to implement a new method,
but my understanding of the queue implementation is too low to decide what
of them is a better approach. ¿Can somebody points me in the right
direccion, explaining a bit how the queue works (upHeap and downHeap) or how
to implement the methods I need?

Thanks for your help,