priority_queue用法总结
程序员文章站
2022-07-12 16:51:54
...
#include<bits/stdc++.h>
#include<queue>
using namespace std;
struct cmp1{
bool operator()(int a,int b){
return a>b;//最小值优先
}
};
struct cmp2{
bool operator()(int a,int b){
return a<b;//最大值优先
}
};
struct Node1{
int x;
bool operator<(const Node1& b)const{
return x>b.x;//最小值优先
}
} ;
struct Node2{
int x;
bool operator<(const Node2& b)const {
return x<b.x;//最大值优先
}
};
int main(){
priority_queue<int> q0; //默认优先级,也就是最大优先
priority_queue<int,vector<int>,cmp1> q1;
priority_queue<int,vector<int>,cmp2> q2;
priority_queue<int,vector<int>,less<int> > q3;//小于仍旧是小于,最大值优先
priority_queue<int,vector<int>,greater<int> > q4;//最小值优先
priority_queue<Node1> q5;//最小值优先
priority_queue<Node2> q6;//最大值优先
}