先进先出
#include<queue> #include<iostream> #include<algorithm> using namespace std; struct cmp{ operator ()(string &a,string &b){ if(a[0] != b[0])return a[0] < b[0]; else return a > b; } }; //运算符重载 struct student{ int grade; string name; friend bool operator < (student a, student b){ return a.grade > b.grade; } }; int main(){ priority_queue<int>q; //大的优先 priority_queue<int,vector<int>,greater<int> >q; //小的优先 //自定义优先级 priority_queue<string,vector<string>,cmp>q; //结构体 student s[4] = { {67,"Kite"}, {59,"Tom"}, {100,"Jim"}, {98,"Mark"} }; priority_queue<student>q; return 0; }
原文:https://www.cnblogs.com/Cmathe/p/12262719.html