#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
class Test
{
public:
int a;
string b;
bool operator<(const Test &t)const
{
if (t.a == this->a)
{
return t.b > this->b;
}
return t.a > this->a;
}
};
int main()
{
priority_queue<Test, vector<Test>>q;
q.push({ 11,"aa" }), q.push({ 12,"aa" }), q.push({ 13,"bb" });
int size = q.size();
for (int i = 0;i < size;i++)
{
cout << q.top().a << " " << q.top().b << endl;
q.pop();
}
return 0;
}
[C++]-关于优先队列的比较运算符的重载
最新推荐文章于 2024-06-30 20:23:11 发布