# Include
# Define N 20int main () {void heapSort (int *, int); int I, a [N + 1]; printf ("Enter twenty numbers: \ n "); for (I = 1; I <= N; I ++)/* because the heap sorting uses a Complete Binary Tree, therefore, the storage of elements must start from 1 */scanf ("% d", a + I); heapSort (a, N); for (I = 1; I <= N; I ++) printf ("% d", a [I]); return 0 ;} /* This function completes the adjustment of nodes on the low position in the range from array a [low] to a [high] */void Sift (int * a, int low, int high) {int I = low, j = I * 2;/* a [j] is the left child node of a [I] */int temp = a [I]; /* Save the node on low */while (j <= high) {if (j
= 2; -- I)/* perform n-1 cycles to complete heap sorting */{temp = a [1];/* replace the elements in the root node with the following three sentences, place it in the final location */a [1] = a [I]; a [I] = temp; Sift (a, 1, I-1 ); /* this time, you only need to adjust the root node, and the number of elements is reduced by 1 */}}