sort对第三个参数的使用
template<typename _RandomAccessIter, typename _Tp, typename _Compare>
void
__unguarded_linear_insert(_RandomAccessIter __last, _Tp __val, _Compare __comp)
{
_RandomAccessIter __next = __last;
--__next;
while (__comp(__val, *__next)) {
*__last = *__next;
__last = __next;
--__next;
}
*__last = __val;
}
bool com(int a, int b)
返回为真时的条件,就是 a排在b前面的条件
struct comp
{
bool operator()(const int &x, const int &y)const
{
return x > y;
}
};std make_heap
struct heap_cmp {
bool operator() (const heap_item *item1, const heap_item *item2) const {
return item1->key < item2->key;
}
};
堆顶要求是value最大的元素
返回true时,第二个参数,value大
返回true时,第二个参数会去堆顶
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: C++ STL中sort()原理浅解
- 下一篇: 详细解说 STL 排序(Sort)
