-->
当前位置:首页 > 题库 > 正文内容

程序填空题:Inserts X into a max-heap H

Luz4年前 (2021-05-10)题库892
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 ]

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。