您的位置:首页 > 其它

优先队列——重载运算符

2015-08-10 19:57 218 查看
#include<iostream>

#include<queue>

#include <algorithm>

#define PQ priority_queue

using namespace std;

struct sq

{

int a,b;

friend bool operator < (sq x,sq y)

{

return x.a>y.a;

}

};

int main()

{

int i,j,m,n,k;

sq s[100],l[100];

PQ<sq> x;

for (i=0;i<100;i++)

{

s[i].a=rand() % 100;

s[i].b=rand() % 100;

x.push(s[i]);

}

while (!x.empty())

{

cout << x.top().a<<' '<<x.top().b<<endl;

x.pop();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  小知识