#include <iostream>
using namespace std;
void exchange(int a[], int i, int j)
{
int temp = a;
a = a[j];
a[j] = temp;
}
void adjustTree(int a[], int i, int total)
{
int l = i * 2;
int r = i * 2 + 1;
//取左右孩子中最大的
int maxIndex = -1;
if(l <= total && a[l] > a)
{
maxIndex = l;
}
else
maxIndex = i;
if(r <= total && a[r] > a[maxIndex])
{
maxIndex = r;
}
if(maxIndex != i)
{
exchange(a, i, maxIndex);
//TODO 优化
adjustTree(a, maxIndex, total);
}
}
void buildTree(int a[], int total)
{