首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于优先队列,该如何解决

2013-07-08 
关于优先队列本帖最后由 leizh007 于 2013-06-13 18:44:02 编辑In their implementation in the C++ Stand

关于优先队列
本帖最后由 leizh007 于 2013-06-13 18:44:02 编辑 In their implementation in the C++ Standard Template Library, priority queues take three template parameters:
1
2
template < class T, class Container = vector<T>,
           class Compare = less<typename Container::value_type> > class priority_queue;

Where the template parameters have the following meanings:
T: Type of the elements.
Container: Type of the underlying container object used to store and access the elements.
Compare: Comparison class: A class such that the expression comp(a,b), where comp is an object of this class and a and b are elements of the container, returns true if a is to be placed earlier than b in a strict weak ordering operation. This can either be a class implementing a function call operator or a pointer to a function. This defaults to less<T>, which returns the same as applying the less-than operator (a<b).
The priority_queue object uses this expression when an element is inserted or removed from it (using push or pop, respectively) to grant that the element popped is always the greatest in the priority queue.

比如我定义这个
priority_queue<int,vector<int>,less<int> > q;
比如less(1,2)=true,那1的优先级高还是2的优先级高,1排在前面还是后面?
这句话没看懂
A class such that the expression comp(a,b), where comp is an object of this class and a and b are elements of the container, returns true if a is to be placed earlier than b in a strict weak ordering operation.
谢谢

再比如我随便定义一个比较函数
f(a,b)=true的时候是a先输出还是b呢?

粗略看过c,那本c++ primer快看完了。还是不知道怎么编个软件,只会去oj a两道题。
接下来我还要看什么,mfc吗?
谁能在这儿里面找个最小的程序给我,我学习一下?不知道怎么按大小排序:http://www.oschina.net/project/lang/21/c
要看懂这里面的东西还要看什么书?
[解决办法]
comp(a,b)==true 的时候 a 排在 b 前面,你问题中的 less 和 f 也是同样的行为。c++ primer 是讲语言的,不是讲软工的。

热点排行