#include <stdio.h>
void AdjustHeapSort(int a[],int root,int last){
int child;
a[0]=a[root];
for(;2*root<=last;root=child){
child=2*root;
if(child+1<=last && a[child]<a[child+1]){
child++;
}
if(a[child]<=a[0]){
break;
}
else {
a[root]=a[child];
a[child]=a[0];
}
}
a[child]=a[0];
}
void BuildMaxHeap(int a[],int length){
for(int i=length/2;i>=1;i--){
AdjustHeapSort(a,i,length);
}
}
void HeapSort(int a[],int length){
BuildMaxHeap(a,length);
for(int i=length;i>1;i--){
a[0]=a[1];
a[1]=a[i];
a[i]=a[0];
AdjustHeapSort(a,1,i-1);
}
}
int main () {
int array[11]={89,98,56,65,41,14,23,32,70,39,56};
HeapSort(array,10);
for(int i=1;i<10;i++){
printf("%d, ",array[i]);
}
return 0;
}