小编cau*_*n14的帖子

在boost中定义fibonacci堆的比较函数

我需要在我的项目中使用Fibonacci堆,我试图从boost库中使用它.但我无法弄清楚如何为任意数据类型设置用户定义的比较函数.我需要为struct node构造一个min heap,如下所示:

struct node
{
    int id;
    int weight;
    struct node* next;
                 /* dist is a global array of integers */
    bool operator > (struct node b)                                 //Boost generates a Max-heap. What I need is a min-heap.
            {return dist[id]   < dist[b.id] ? 1:0  ;}               //That's why "<" is used for "operator >".
    bool operator < (struct node b)
            {return dist[id]   > dist[b.id] ? 1:0 ;}
    bool operator >=(struct node b)
            {return dist[id]   <= dist[b.id] ? 1:0 ;}
    bool operator …
Run Code Online (Sandbox Code Playgroud)

c++ templates boost fibonacci-heap

5
推荐指数
1
解决办法
5010
查看次数

标签 统计

boost ×1

c++ ×1

fibonacci-heap ×1

templates ×1