static void HeapSort(int[] a){
for(int i=a.length/2-1; i>=0; i--){
adjustHeap(a, i, a.length-1);
}
for(int i=a.length-1,temp; i>=1; i--){
temp = a[0];
a[0] = a[i];
a[i] = temp;
adjustHeap(a, 0, i-1);
}
}
static void adjustHeap(int[] a, int fromIndex, int toIndex){
int key = a[fromIndex],temp;
for(int i=2*fromIndex; i<=toIndex; i*=2){
if(i<toIndex && a[i]<a[i+1])i++;
if(key >= a[i])break;
temp = a[fromIndex];
a[fromIndex] = a[i];
a[i] = temp;
fromIndex = i;
}
a[fromIndex] = key;
}