关于优先队列重载运算符的问题
int类型的优先队列从小到大
本来priority_queue< int,vector<int>,greater<int> > que;这样定义就行了
但是今天做了hdu上的一题,楞是编译不过,说是greater未声明,poj上一模一样的题反倒AC
然后我搜了一下,发现有人这么重载了括号就行了。。。实在是不理解。。。
class mycomparison
{
public:
bool operator() (const int& lhs, const int&rhs) const
{
return (lhs > rhs);//使得从小到大排序,队列头为最小元素,优选权队列默认队列头最大
}
};
priority_queue<int, vector<int>, mycomparison> pq;
为什么重载的是括号呢- -
如果在greater<int>无法用的情况下 大家自己又会想到怎么做呢?我直接定义两个参数为int类型的比较的函数编译不过。。
或者有人知道为什么hdu编译不过也可以说说。。
谢谢大家啦。