优化
void fall(vector<int>&arr, int heapSize, int fallIndex)
{
int l = fallIndex * 2 + 1;
int r = fallIndex * 2 + 2;
if (r < heapSize)//右节点的序号小于数组大小
{
int maxChild = arr[l] > arr[r] ? l : r;
if (arr[fallIndex] < arr[maxChild])
{
swap(arr[fallIndex], arr[maxChild]);
fall(arr, heapSize, maxChild);
}
}
else if (l < heapSize)//只有左节点
{
if (arr[fallIndex] < arr[l])
{
swap(arr[fallIndex], arr[l]);
fall(arr, heapSize, l);
}
}