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

程序填空题:Insert an element X into a min heap

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

发表评论

访客

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