void HeapAdjust(int *arr, int start, int end)
{
int tmp=arr[start];
int child=2*start+1;
while(child <= end)
{
if(child<end && arr[child]<arr[child+1]) child++;
if(arr[child]>tmp)
{
arr[start]=arr[child];
start=child;
child=2*start+1;
}
else
break;
}
arr[start] = tmp;
}
int *HeapSort(int *arr, int len)
{
for(int i=len/2; i>=0; i--)
{
HeapAdjust(arr, i, len-1);
}
for(int i=len-1; i>0; i--)
{
int tmp=arr[i];
arr[i]=arr[0];
arr[0]=tmp;
HeapAdjust(arr,0,i-1);
}
return arr;
}