本来想用 priority_queue 去写个bfs。结果重载运算符忘了。ORZ。
然后看书和问别人熟悉了一下,记录一下。
struct lx
{
int x,y,lv;
};struct lx
{
int x,y,lv;
friend bool operator<(lx a,lx b)
{
return a.lv>b.lv;
}
};或者
struct lx
{
int x,y,lv;
bool operator < (lx a)const
{
return lv>a.lv;
}
};
然后就可以直接
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;
C++重载运算符 < priority_queue 相关(个人笔记)
原文地址:http://blog.csdn.net/dongshimou/article/details/39395373