#include <iostream>
#include <queue>
#include <map>
#include <set>
using namespace std;
struct cmp1 {
bool operator()(int a,int b) {
if (a<b) {
return true; //此时是大根堆 若想建小根堆 则改为a>b
}
else {
return false;
}
}
};
bool cmp(int a, int b) {
if (a < b) {
return true;
}
else {
return false;
}
}
int main()
{
priority_queue<int, vector<int>, cmp1>que; //此时是大根堆
set<int, cmp1>s; //按key值递增顺序
map<int,int,cmp1>m; //按key值递增顺序
vector<int>v;
sort(v.begin(),v.end(),cmp);//递增排序
return 0;
}
note:优先级队列也就是堆初始化时必须要多加一个参数,priority_queue<int, vector, cmp1>que,cmp1为仿函数,堆还有一点和其他容器不同的是a<b时为大根堆。
vector容器初始化时不能加入任何比较器,只能调用sort时加入比较器。