#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct cmp {
bool operator()(int a,int b){
return a > b;
}
};
struct cmp1{
bool operator()(int a,int b){
return a <b;
}
};
int priority_q_method(){
//priority_queue<int> priority_q;//默认由大到小
//priority_queue<int, vector<int>, greater<int> >priority_q;//有小到大,vs studio中无法使用该模板
//priority_queue<int, vector<int>, less<int> >priority_q;//由大到小
//priority_queue<int, vector<int>, cmp >priority_q;//由小到大
priority_queue<int, vector<int>, cmp1 >priority_q;//由大到小
priority_q.push(2);
priority_q.push(3);
priority_q.push(1);
while(!priority_q.empty()){
int q = priority_q.top();
priority_q.pop();
printf("%d\n",q);
}
return 0;
}
[C++] 优先队列(priority_queue)排序方式模板
最新推荐文章于 2024-09-18 19:13:26 发布