1. 程式人生 > >sort對第三個引數的使用

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;
    }   
};

返回true的條件,就是第一個引數比第二個引數有較小的value的條件,堆頂是要有最大value的值,小於為真,最大堆,大於為真,最小堆

堆頂要求是value最大的元素

返回true時,第二個引數,value大

返回true時,第二個引數會去堆頂