I want to keep two things in my priority queue…one is a number and the other is cost. i.e. I want to do the following:
PriorityQueue<Integer, Cost> q=new PriorityQueue<Integer, Cost>();
Cost is another class that i hav:
class Cost implements Comparable<Cost>
{
String name;
double cost;
@Override
public int compareTo(Cost s)
{
return Double.compare(cost, s.cost);
}
}
Also I want to perform comparisons only based on cost…but I also want some integer identifier to be passed along with cost…is there some way to achieve this?
i need to retrieve Cost based on id..therefore I am using a hash map for it. When using an id field in cost…i want to retrieve the entire cost instance based on that id field…is it possible…is yes, then how?
I am a novice at Java programming. Can someone pls suggest some way out?
Change your
CostclassThen you can simply declare
PriorityQueueofConstNow when you want to find
Costbased onidyou can do below