运算符重载<
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#define inf 0x3f3f3f3f
using namespace std;
struct node
{
int x,y;
}q[100];
priority_queue<node> pq;
bool operator <(struct node a,struct node b)//只能重载<,从小到大排列
{
return a.x>b.x;
}
int main()
{
q[0].x=1;q[0].y=2;
q[1].x=3;q[1].y=2;
q[2].x=2;q[2].y=2;
for(int i=0;i<=2;i++)
pq.push(q[i]);
for(int i=0;i<=2;i++)
{
cout<<pq.top().x<<endl;
pq.pop();
}
return 0;
}
输出:
转载请注明原文地址: https://ju.6miu.com/read-1295624.html