#include<cstdio> #include<queue> #include<vector> using namespace std; struct cmp{ bool operator()(const int &a,const int &b) { return a>b; //if(a<b) return false;等效 //< 为降序排序 大根堆 } }; int main() { priority_queue<int> pque; pque.push(0); pque.push(3); pque.push(5); pque.push(1); while(!pque.empty()) { printf("%d ",pque.top());//默认从大到小 pque.pop(); } printf("\n"); priority_queue<int,vector<int>,cmp> pq;//注意vector拼写 // priority_queue<int,vector<int>,greater<int> > pq; 等效 pq.push(0); pq.push(3); pq.push(5); pq.push(1); while(!pq.empty()) { printf("%d ",pq.top()); pq.pop(); } return 0; }
10
22
2015
22
2015