sort對第三個引數的使用
阿新 • • 發佈:2019-01-05
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時,第二個引數會去堆頂