关于优先队列
priority_queue<int, vector<int>, less<int> > que; 从大到小排序。
priority_queue<int, vector<int>, greater<int> > que;从小到大排列。
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main(){ 5 ios::sync_with_stdio(false); 6 priority_queue<int, vector<int>, less<int> > que; 7 que.push(2); 8 que.push(4); 9 que.push(0); 10 cout<<que.top()<<" "; 11 que.pop(); 12 cout<<que.top()<<endl; 13 return 0; 14 }
结果:
4 2
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main(){ 5 ios::sync_with_stdio(false); 6 priority_queue<int, vector<int>, greater<int> > que; 7 que.push(2); 8 que.push(4); 9 que.push(0); 10 cout<<que.top()<<" "; 11 que.pop(); 12 cout<<que.top()<<endl; 13 return 0; 14 }
结果:
0 2