I have declare a priority queue for with minimum element at the top as follows
priority_queue<int, vector<int> , greater<vector<int>> > low;
Now I want to pass this object to some function, for this i need to declare in function header, I tried declaring following ways
int fun1(priority_queue<int, vector<int> , greater<vector<int>> > min_heap){
return 0;
}
int fun2(priority_queue<int> min_heap){
return 0;
}
in both approach i am getting compilation error; second approach is obvious to give error because of type mismatch but compiler does not allow to do first approach. Please help me.
You should post the compiler error, but I'm going to try to guess your problem even without it.
Your declaration is probably wrong, that is, your:
priority_queue<int, vector<int> , greater<vector<int>> > low;
should be instead:
priority_queue<int, vector<int> , greater<int> > low;
Note the third template parameter.
Since you have a queue
of int
the comparator has to be defined over, indeed, int
and not on std::vector<int>
.
In that way should compiler. Here an example.