我需要在我的项目中使用斐波那契堆,我正在尝试从 boost 库中使用它。但我无法弄清楚如何为任意数据类型设置用户定义的比较函数。我需要为结构节点构造一个最小堆,定义如下:
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 <=(struct node b)
{return dist[id] >= dist[b.id] ? 1:0 ;}
node()
{
id=0;
weight=0;
next=NULL;
}
};
我查阅了文档,有一个比较类。但它不包含任何元素。请告诉我如何设置用户定义的比较功能。先感谢您。