I am implementing a version of the A*-pathfinding algorithm for Android. I use a PriorityQueue to manage my openList
.
In some cases I update the prioritizing-attribute of one of the queue's entries. If I call remove()
, to get the head-Object on the updated queue, expecting to get the updated entry, I get wrong results. It seems not to prioritize the updated queue correctly.
The only solution I found was to remove the specific entry, update the value and put it back in like so:
openList.remove(objectToBeUpdated);
objectToBeUpdated.setPriorityAttribute(newValue);
openList.add(objectToBeUpdated);
It seems like the queue does prioritize when adding objects, not by polling/removing them?
Is there another way than removing and adding it again? Its such a dirty solution, i think. Or is this just the PriorityQueue's behaviour and I have to deal with it?