qsort make_heap

</pre><p></p><pre name="code" class="cpp">#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

int main(){
	int array[]={21,5,68,73,4,98,6,3};
	make_heap(array,array+8);
	for(int i=0;i<8;i++)
		cout<<array[i]<<" ";
	cout<<"ddddd"<<endl;
	return 0;
}





Binary function that accepts two elements in the range as arguments, and returns a value convertible to 
bool. The value returned indicates whether the element passed as first argument is considered to be 
less than the second in the specific strict weak ordering it defines.

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

小於爲真,最大堆,大於爲真,最小堆



return value meaning
<0 The element pointed by p1 goes before the element pointed by p2
0 The element pointed by p1 is equivalent to the element pointed by p2
>0 The element pointed by p1 goes after the element pointed by p2

int compareMyType (const void * a, const void * b)
{
  if ( *(MyType*)a <  *(MyType*)b ) return -1;
  if ( *(MyType*)a == *(MyType*)b ) return 0;
  if ( *(MyType*)a >  *(MyType*)b ) return 1;
}

發佈了46 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章