</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.
小於爲真,最大堆,大於爲真,最小堆
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;
}