int main() {
//大顶堆
std::priority_queue<int >q; // 等同于 std::priority_queue<int,std::vector<int> , std::less<int> >q;
for(int n : {1,8,5,6,3,4,0,9,7,2})
q.push(n);
print_queue(q);
//小顶堆
std::priority_queue<int,std::vector<int> , std::greater<int> >q2;
for(int n : {1,8,5,6,3,4,0,9,7,2})
q2.push(n);
print_queue(q2);
//------------------------自定义lambar比较------------------------------
// Using lambda to compare elements.
auto cmp = [](int left, int right) { return (left ^ 1) < (right ^ 1); };
std::priority_queue<int, std::vector<int>, decltype(cmp)> q3(cmp);
for(int n : {1,8,5,6,3,4,0,9,7,2})
q3.push(n);
print_queue(q3);
}
set
#include <bits/stdc++.h>
struct cmp {
bool operator()(int x, int y) { return x > y; }
};
struct cmp1 {
bool operator()(const int &x, const int &y) const { return x > y; }
};
int main() {
set<int, cmp> st;
st.insert(5);
st.insert(3);
cout << *st.begin() << '\n';
return 0;
}