1.重载运算符
理解并不难,主要是格式值得注意。
另外要注意在队列中要注意排序的顺序,q.top()/q.front() 访问的是队首元素,如果queue是升序,q.front()就是最大的;
#include <iostream>
#include <queue>
using namespace std;
struct student {
string name;
int score;
};
struct cmp {
bool operator()(const student& a, const student& b) const {
return a.score < b.score || (a.score == b.score && a.name > b.name);
}
};
priority_queue<student, vector<student>, cmp> pq;
int main() {
return 0;
}
2.sort
当用sort排序vector时,这样写:
sort(vector.begin() , vector.end() , cmp);
标签:sort,vector,const,name,杂七杂八,知识,score,student
From: https://www.cnblogs.com/Hutaooo/p/17616567.html