程序填空题:Merge two leftist heaps
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
```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