#include<bits/stdc++.h>
using namespace std;
struct node
{
int d;
bool operator < (const node &a ) const{ //重载操作符 < 改为> 大根堆优先node队列变为小根堆
return d > a.d;
}
};
priority_queue <node> q;
priority_queue <int> p;
int main(void)
{
node t;
t.d = 1;
q.push(t);
t.d = 5;
q.push(t);
t.d = 9;
q.push(t);
t.d = 2;
q.push(t);
t.d = 6;
q.push(t);
while(!q.empty())
{
cout<<q.top().d<<endl;
q.pop();
}
cout<<"***************"<<endl;
p.push(1);
p.push(5);
p.push(9);
p.push(2);
p.push(6);
while(!p.empty())
{
cout<<p.top()<<endl;
p.pop();
}
}
操作符重载 priority_queue <node> q
猜你喜欢
转载自blog.csdn.net/Achanss/article/details/82919326
今日推荐
周排行