I have a hash map of a string and a vertex which is a class.
I want to create a priority queue for an attribute distance of vertex class… How should I do it…
private final PriorityQueue Nodes ;
private HashMap<String,Vertex> c ;
I have to create a priority queue on all the members of the hashmap c according to the vertex.distance value…..
Please tell how should i do that as I always get compilation error on whatever I am trying….
Without knowing your implementation, I give the following answer:
Looking at the javadoc, it appears that there is a constructor which accepts a Comparator. I suspect that what you need to do is create a comparator which corresponds to the vertex.distance value.
So, for example (this is untested code. Treat it as pseudo code):
After that create the
Nodeslike: