void HeapSort(int arr[],int start,int end)
{
int dad = start;
int son = dad * 2 + 1;
while(son<=end)
{
if( son+1<=end && arr[son]< arr[son+1])
son++;
if(arr[dad] > arr[son]) return ;
else {
swap(arr[dad] ,arr[son]);
dad = son;
son = dad * 2 +1;
}
}
}
void Heap(int arr[],int len)
{
for(int i = len/2-1; i>=0;i--)
{
HeapSort(arr,i,len);
}
for(int i = len-1;i>0;i--)
{
swap(arr[0],arr[i]);
HeapSort(arr,0,i-1);
}
}
标签:dad,arr,int,HeapSort,堆排序,len,son
From: https://www.cnblogs.com/shenxiaodou/p/16712360.html