程序填空题:Inserts X into a max-heap H
Please fill in the blanks in the program which inserts X into a max-heap H.
```c++
/* H->Element[ 0 ] is a sentinel */
void Insert( ElementType X, PriorityQueue H )
{
int i;
if ( IsFull( H ) ) {
Error( "Priority queue is full" );
return;
}
for ( i = ++H->Size; @@[H->Elements[ i / 2 ] < X](3); i /= 2 )
@@[H->Elements[ i ] = H->Elements[ i / 2 ]](3);
H->Elements[ i ] = X;
}
```
答案:
第1空:H->Elements[ i / 2 ] < X
第2空:H->Elements[ i ] = H->Elements[ i / 2 ]
```c++
/* H->Element[ 0 ] is a sentinel */
void Insert( ElementType X, PriorityQueue H )
{
int i;
if ( IsFull( H ) ) {
Error( "Priority queue is full" );
return;
}
for ( i = ++H->Size; @@[H->Elements[ i / 2 ] < X](3); i /= 2 )
@@[H->Elements[ i ] = H->Elements[ i / 2 ]](3);
H->Elements[ i ] = X;
}
```
答案:
第1空:H->Elements[ i / 2 ] < X
第2空:H->Elements[ i ] = H->Elements[ i / 2 ]