提升优先级队列比较功能 [英] Boost priority queue comparison function

查看:143
本文介绍了提升优先级队列比较功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变优先级队列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< D​​istanceTuple,性病::矢量< 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆