【发布时间】:2018-09-18 07:37:22
【问题描述】:
当我在std::sort中使用std::greater<int>作为比较函数对象时如下:
std::sort(array_name, array_name + length, std::greater<int>());
按非递增顺序排序的数组(即最大的数在前)
但是,当我在std::priority_queue 中使用相同的比较函数时:
std::priority_queue <int, std::vector<int>, std::greater<int> > pq_name;
为什么std::priority_queue::top成员函数先返回最小的数?
(我需要对这两种情况进行清晰的比较)。
【问题讨论】:
-
如果您先阅读最小堆和最大堆之间的区别可能会更清楚。
-
@codekaizer 好的,我现在正在阅读它,这似乎是您的有用提示,谢谢。
标签: c++ stl heap priority-queue