本来想用 priority_queue 去写个bfs。结果重载运算符忘了。ORZ。
然后看书和问别人熟悉了一下,记录一下。
struct lx
{
int x,y,lv;
};
有一个这样的结构体。x,y,是坐标,lv 是它的权。重载<。
struct lx
{
int x,y,lv;
friend bool operator<(lx a,lx b)
{
return a.lv>b.lv;
}
};
friend !友员
或者
struct lx
{
int x,y,lv;
bool operator < (lx a)const
{
return lv>a.lv;
}
};
要通过STL 必须加上const 修饰。
然后就可以直接
priority_queue<lx> q;
或者不写重载,自己定义priority_queue的Compare函数
struct cmp
{
bool operator()(lx a,lx b)
{
return a.lv<b.lv;
}
};
priority_queue<lx,vector<lx>,cmp>q;
感觉还是重载了。。。。就这样吧,马上去用priority_queue 去优化一下bfs。