输入数字 1 4 3 10
样例输出 10 4 3 1
#include <iostream>
#include <queue>
using namespace std;
int main(){
priority_queue<int> q;
q.push(1); q.push(10); q.push(3); q.push(4);
while(!q.empty ()){
int s;
s=q.top ();
cout<<s<<" ";
q.pop();
}
return 0;
}
改变比较函数
#include <iostream>
#include <queue>
using namespace std;
int main(){
priority_queue<int, vector<int>, greater<int> > q;
q.push(0); q.push (10); q.push(5); q.push (2);
while(!q.empty()) {
int x;
x=q.top(); q.pop();
cout<<x<<" ";
}
cout<<endl;
return 0;
}