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

程序填空题:Delete a node with minimal key from a min-heap

Luz4年前 (2021-05-10)题库482
The function is to delete the node with minimal key from a min-heap H.

```c++
ElementType DeleteMin( PriorityQueue H )
{
int i, Child;
ElementType MinElement, LastElement;

MinElement = H->Elements[ 1 ];
LastElement = H->Elements[ H->Size-- ];
for ( i = 1; i * 2 <= H->Size; i = Child ) {
Child = i * 2;
if (Child != H->Size && @@[H->Elements[Child+1] < H->Elements[Child]](3))
Child++;
if ( LastElement > H->Elements[ Child ] )
@@[H->Elements[ i ] = H->Elements[ Child ]](3);
else break;
}
H->Elements[ i ] =  LastElement;
return MinElement;
}


```





答案:
第1空:H->Elements[Child+1] < H->Elements[Child]

第2空:H->Elements[ i ] = H->Elements[ Child ]

发表评论

访客

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