程序填空题:Find the Kth largest integer from a list
The function is to find the Kth largest integer from a list A of N(>K) integers. The function BuildMinHeap(H, K) is to arrange integers H[1] ... H[K] into a min-heap.
```c++
int FindKthLargest ( int A[], int N, int K )
{
int *H, i, next, child;
H = (int *)malloc(++N, sizeof(int));
for ( i=1; i BuildMinHeap(H, K);
for ( next=K+1; next < N; next++ ) {
H[0] = H[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[child]](3))
H[i] = H[child];
else break;
}
@@[H[i] = H[0]](3);
}
}
return @@[H[1]](3);
}
```
答案:
第1空:H[child+1] < H[child]
第2空:H[0] > H[child]
第3空:H[i] = H[0]
第4空:H[1]
```c++
int FindKthLargest ( int A[], int N, int K )
{
int *H, i, next, child;
H = (int *)malloc(++N, sizeof(int));
for ( i=1; i
for ( next=K+1; next < N; next++ ) {
H[0] = H[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[child]](3))
H[i] = H[child];
else break;
}
@@[H[i] = H[0]](3);
}
}
return @@[H[1]](3);
}
```
答案:
第1空:H[child+1] < H[child]
第2空:H[0] > H[child]
第3空:H[i] = H[0]
第4空:H[1]