C++STL系列 结构体运算符重载及优先队列的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cnyali/article/details/78091532
#include<bits/stdc++.h>
using namespace std;
struct node{
	int x,y;
	bool operator <(const node b)const{
		return this->x>b.x;
	}
};
priority_queue <node> q;
int main(){
	int i,j,k,m,n;
	cin>>n;
	for(i=1;i<=n;i++){
		node t;
		cin>>t.x>>t.y;
		q.push(t);
	}
	while(!q.empty()){
		node t=q.top();
		cout<<t.x<<" "<<t.y<<endl;
		q.pop();
	}
	return 0;
}
//priority_queue < int ,vector<int> , greater<int> > q;
 /*
input:
3
33 11
2 55
15 8
out:
2 55
15 8
33 11
*/


猜你喜欢

转载自blog.csdn.net/cnyali/article/details/78091532