访问次数:1

priority_queue 练习 | Wenji's blog
头部背景图片
WenJi's blog |
|

priority_queue 练习

##代码 greater算子

#include

#include
using namespace std;
class T
{
public:
int x,y,z;
T(int a,int b,int c):x(a),y(b),z(c)
{

}    

};
bool operator >(const T &t1,const T &t2)
{
return t1.z>t2.z;
}
int main()
{
priority_queue<T,vector,greater > q;
q.push(T(4,4,3));
q.push(T(2,2,5));
q.push(T(1,5,4));
q.push(T(3,3,6));
while(!q.empty())
{
T t=q.top();
q.pop();
cout<<t.x<<” “<<t.y<<” “<<t.z<<endl;
}
return 0;
}

##代码 less 算子

#include

#include
using namespace std;
class T
{
public:
int x,y,z;
T(int a,int b,int c):x(a),y(b),z(c)
{

}    

};
bool operator <(const T &t1,const T &t2)
{
return t1.z<t2.z;
}
int main()
{
priority_queue q;
q.push(T(4,4,3));
q.push(T(2,2,5));
q.push(T(1,5,4));
q.push(T(3,3,6));
while(!q.empty())
{
T t=q.top();
q.pop();
cout<<t.x<<” “<<t.y<<” “<<t.z<<endl;
}
return 0;
}

Dear friends TRIPLANE

Not available

- 00:00 / 00:00
  1. 1 Dear friends TRIPLANE
  2. 2 Butter-Fly 和田光司
  3. 3 宵闇花火 葉月ゆら