stl优先级队列基于较低的值先 [英] stl priority queue based on lower value first

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

问题描述

我有一个stl优先级队列的问题。我希望有优先级队列在增加
的顺序,这是递减的默认值。有任何方法在优先级队列这样做。

I have a problem with stl priority queue.I want to have the priority queue in the increasing order,which is decreasing by default.Is there any way to do this in priority queue.

构建stl优先级队列的复杂性是什么。如果我在数组中使用快速排序,需要O(nlgn),它的复杂性类似于使用优先队列

And what is the complexity of building stl priority queue.If i use quick sort in an array which takes O(nlgn) is its complexity is similar to using priority queue???

Plz有人ans.Advanced thanx。

Plz someone ans.Advanced thanx.

推荐答案

使用不同的比较器作为 std :: priority_queue

Use a different comparator as the 3rd template argument of std::priority_queue.

priority_queue是一个容器适配器,适用于您定义的任何序列。插入的性能等于 std :: push_heap 操作,并取对数时间。因此,在完成所有插入之后排序的复杂性不相等。如果你插入一个固定的数量,并在队列后工作向量和单个排序可能会更有效率。

priority_queue is a container adaptor that works on any sequence you define. The performance of insertion is equal to the std::push_heap operation and takes logarithmic time. So the complexity to sorting after all insertions are done isn't equal. If you insert a fixed amount and work the queue afterwards a vector and a single sort could be more efficient.

这篇关于stl优先级队列基于较低的值先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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