vector
https://blog.csdn.net/weixin_42172261/article/details/86604772
map
https://blog.csdn.net/weixin_42172261/article/details/86621807
set
https://blog.csdn.net/weixin_42172261/article/details/86607669
迭代器
https://blog.csdn.net/weixin_42172261/article/details/86606300
stack
https://blog.csdn.net/weixin_42172261/article/details/88924120
queue
https://blog.csdn.net/weixin_42172261/article/details/88924295
priority_queue
#include <iostream>
#include <queue>
#include <ctime>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main(){
//从大到小排列
priority_queue<int, vector<int>, less<int> > q;
srand((unsigned)time(NULL));
for (int i=1; i<=5; i++){
int t = rand() % 20;
q.push(t);
}
while (!q.empty()){
int t = q.top();
q.pop();
cout<<t<<endl;
}
return 0;
}
//从小到大排列
priority_queue<int, vector<int>, greater<int> > q;
#include <iostream>
#include <queue>
#include <ctime>
#include <cstdlib>
using namespace std;
//重载小于号,a和b越大的优先级越低,越排在后面
struct Node{
int a, b;
bool operator<(const Node& t) const{
if (a!=t.a) return a>t.a;
else return b>t.b;
}
};
int main(){
priority_queue<Node> q;
srand((unsigned)time(NULL));
for (int i=1; i<=5; i++){
Node t;
t.a = rand() % 20;
t.b = rand() % 20;
q.push(t);
}
while (!q.empty()){
Node t = q.top();
q.pop();
cout<<t.a<<" "<<t.b<<endl;
}
return 0;
}
//重载小于号,a和b越小的优先级越低,越排在后面
struct Node{
int a, b;
bool operator<(const Node& t) const{
if (a!=t.a) return a<t.a;
else return b<t.b;
}
};