提升优先级队列比较功能 [英] Boost priority queue comparison function
问题描述
如何改变优先级队列Boost库比较函数?
我有这样的结构:
How to change comparison function on a priority queue with boost library? I have a struct like this :
struct decreasingOrderMyType
{
bool operator() (const MyType & lhs, const MyType & rhs) const
{
return lhs.value > rhs.value;
}
};
和我想用它来比较我的元素。
and i would like use it to compare my elements.
谢谢!
推荐答案
有关在std :: priority_queue我把它规定为:的std :: priority_queue< DistanceTuple,性病::矢量< DistanceTuple>中SmallestOnTop> PQ;
For the std::priority_queue I have it specified as: std::priority_queue<DistanceTuple, std::vector<DistanceTuple>, SmallestOnTop > pq;
DistanceTuple
是的std ::对
和 SmallestOnTop
是一个仿函数比较的std ::对
DistanceTuple
is a std::pair
and SmallestOnTop
is a functor to compare the std::pair
更新:我错了,它们并不相同。升压版本使用命名参数。像这样的工作,其中:
Update: I was wrong, they are not identical. The boost version uses named parameters. Which work like this:
boost::heap::priority_queue<MyType,
boost::heap::compare<decreasingOrderMyType> > pq;
这篇关于提升优先级队列比较功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!