I want to know an easy way to obtain a (Map + min-Heap) data structure in C++
I tried this:
struct Comp
{
bool operator()(const pair<int,int>& y , const pair<int,int>& z)
{
return (y.second < z.second);
}
};
priority_queue< pair<int,int> , map<int,int> , Comp > p;
now the problem I face is with re-initialisation since it is in priority_queue
we can't just simply initialise like we do with maps
.
The only way to insert element is
p.push(make_pair(value1,value2));
I have also tried to use simple maps instead of using it with priority_queue
but the problem again is when I try to find the minimum element using min_element
it returns the value instead of the key which is also required here.
Please suggest the fastest possible way to execute the problem. I also believe that there are ways possible beyond my knowledge.