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

程序填空题:Merge two leftist heaps

Luz4年前 (2021-05-10)题库1928
The function is to merge two leftist heaps H1 and H2.

```c++
PriorityQueue Merge( PriorityQueue H1, PriorityQueue H2 )
{
if (H1==NULL) return H2;
if (H2==NULL) return H1;
if (@@[H1->Element > H2->Element](3))
swap(H1, H2); //swap H1 and H2
if ( H1->Left == NULL )
@@[H1->Left = H2](3); ;
else {
H1->Right = Merge( H1->Right, H2 );
if ( H1->Left->Npl < H1->Right->Npl )
SwapChildren( H1 ); //swap the left child and right child of H1
@@[H1->Npl = H1->Right->Npl + 1](3) ;
}
return H1;
}

```





答案:
第1空:H1->Element > H2->Element

第2空:H1->Left = H2

第3空:H1->Npl = H1->Right->Npl + 1

发表评论

访客

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