How to find the index of an item in a PriorityQueue? (Java)

I was wondering if I managed to find the index of the value in PriorityQueue. Just to see what number he is "in line". Somebody knows?

+3
source share
3 answers

There is an index priority queue written by Princeton.

http://algs4.cs.princeton.edu/code/javadoc/IndexMinPQ.html

The key idea is to create two index cards between the element and its position in the priority queue.

When updating the priority queue, you also need to update these two index maps.

Hope this solves your problem :-)

+3
source

PriorityQueue does not support indexing. You can associate an integer index with each element.

+2

, :

An unbounded priority queue based on a priority heap. 

You cannot use a bunch of priorities to efficiently find the index of an element. He knows only the first one, and when you pop it up, he recounts the new first one, etc.

0
source