static void max_heap(int[] num, int start, int end) {
int dad = start;
int son = dad * 2 + 1;
while (son < end) {
if (son + 1 < end && num[son] < num[son + 1])
son++;
if (num[dad] > num[son])
return;
else {
num[dad] ^= num[son];
num[son] ^= num[dad];
num[dad] ^= num[son];
dad = son;
son = dad * 2 + 1;
}
}
}
static void heap_sort(int[] num) {
for (int i = num.length / 2 - 1; i >= 0; --i) {
max_heap(num, i, num.length);
}
for (int i = num.length - 1; i >= 0; --i) {
num[i] ^= num[0];
num[0] ^= num[i];
num[i] ^= num[0];
max_heap(num, 0, i);
}
}