程序填空题:FindKthSmallest
The function is to find the `K`-th smallest element in a list `A` of `N` elements. The function `BuildMaxHeap(H, K)` is to arrange elements `H[1]` ... `H[K]` into a max-heap. Please complete the following program.
```c++
ElementType FindKthSmallest ( int A[], int N, int K )
{ /* it is assumed that K<=N */
ElementType *H;
int i, next, child;
H = (ElementType *)malloc((K+1)*sizeof(ElementType));
for ( i=1; i<=K; i++ ) H[i] = A[i-1];
BuildMaxHeap(H, K);
for ( next=K; next H[0] = A[next];
if ( H[0] < H[1] ) {
for ( i=1; i*2<=K; i=child ) {
child = i*2;
if ( child!=K && @@[H[child+1]>H[child]](3) ) child++;
if ( @@[H[0] H[i] = H[child];
else break;
}
H[i] = H[0];
}
}
return H[1];
}
```
答案:
第1空:H[child+1]>H[child]
第2空:H[0]
```c++
ElementType FindKthSmallest ( int A[], int N, int K )
{ /* it is assumed that K<=N */
ElementType *H;
int i, next, child;
H = (ElementType *)malloc((K+1)*sizeof(ElementType));
for ( i=1; i<=K; i++ ) H[i] = A[i-1];
BuildMaxHeap(H, K);
for ( next=K; next
if ( H[0] < H[1] ) {
for ( i=1; i*2<=K; i=child ) {
child = i*2;
if ( child!=K && @@[H[child+1]>H[child]](3) ) child++;
if ( @@[H[0]
else break;
}
H[i] = H[0];
}
}
return H[1];
}
```
答案:
第1空:H[child+1]>H[child]
第2空:H[0]