从 STL 优先级队列创建最小堆

编程入门 行业动态 更新时间:2024-10-09 05:13:53
本文介绍了从 STL 优先级队列创建最小堆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在从 stl 优先级队列创建一个最小堆.这是我正在使用的课程.

I am creating a min heap from stl priority queue. Here is my class which I am using.

class Plane { private : int id ; int fuel ; public: Plane():id(0), fuel(0){} Plane(const int _id, const int _fuel):id(_id), fuel(_fuel) {} bool operator > (const Plane &obj) { return ( this->fuel > obj.fuel ? true : false ) ; }

};

在 main 中,我因此实例化了一个对象.

In main I instantiate an object thus.

priority_queue<Plane*, vector<Plane*>, Plane> pq1 ; pq1.push(new Plane(0, 0)) ;

我从 xutility 收到一个我无法理解的错误.

I am getting an error from xutility which I am unable to understand.

d:\microsoft Visual Studio 10.0\vc\include\xutility(674): error C2064: term 不计算为采用 2 个参数的函数

d:\microsoft visual studio 10.0\vc\include\xutility(674): error C2064: term does not evaluate to a function taking 2 arguments

对其解决方案的任何帮助将不胜感激.

Any help to its solution would be appreciated.

推荐答案

第三个模板参数必须是一个采用 teo Plane* 的二元函子.您的 Plane 类没有提供.

The third template parameter must be a binary functor taking teo Plane*. Your Plane class does not provide that.

你需要某种形式的东西

struct CompPlanePtrs { bool operator()(const Plane* lhs, const Plane* rhs) const { return lhs->fuel > rhs->fuel ; } };

更多推荐

从 STL 优先级队列创建最小堆

本文发布于:2023-11-29 06:06:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:优先级   队列   最小   STL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!