程序填空题:Insert an element X into a min heap
The function is to insert an element X into a min heap.
```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 ];
@@[H->Elements[ i ] = X ](3) ;
}
```
答案:
第1空: H->Elements[ i / 2 ] > X
第2空:H->Elements[ i ] = X
```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 ];
@@[H->Elements[ i ] = X ](3) ;
}
```
答案:
第1空: H->Elements[ i / 2 ] > X
第2空:H->Elements[ i ] = X