As usual, comparator should return boolean value, indicating whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines.
intmain(){
auto comp = [](int a, int b){ return a < b; }
vector<int> vec = {3,6,7,2,1,9,5,4,8};
priority_queue<int, vector<int, decltype(comp)> pq;
for (int num : vec) pq.push(num);
while (!pq.empty()) {
cout << pq.top() <<" "; // 9,8,7,6,5,4,3,2,1
pq.pop();
}
cout << endl;
}
boolcomp(int a, int b){
return a < b;
}
intmain(){
vector<int> vec = {3,6,7,2,1,9,5,4,8};
priority_queue<int, vector<int, decltype(&comp)> pq(comp);
// priority_queue<int, vector<int, decltype(comp)*> pq(comp);
// in C++20, constructor can be ignored the same as lambda function.
for (int num : vec) pq.push(num);
while (!pq.empty()) {
cout << pq.top() <<" "; // 9,8,7,6,5,4,3,2,1
pq.pop();
}
cout << endl;
}