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

程序填空题:Find X in a binomial queue H

Luz4年前 (2021-05-10)题库899
The function is to find X in a binomial queue H.

```c++
BinTree Find( BinQueue H, ElementType X )
/* To find whether X is in H. Return the node pointer if found, otherwise return NULL */
{
BinTree T, result=NULL;
int i,j;
for(i=0, j=1; j<=H->CurrentSize; i++, @@[j *= 2](3)) { /* for each tree in H */
T= H->TheTrees[i];
if ( @@[X>=T->Element](3)){ /* if need to search inside this tree */
result=RecurFindInTree(T, X)
if (result!=NULL) return result;
}
}
}

BinTree RecurFindInTree( BinTree T, ElementType X )
{
BinTree result=NULL;
if (X==T->Element) return T;
if (T->LeftChild !=NULL && X>=T->LeftChild->Element){
result= RecurFindInTree(T->LeftChild, X);
if (result!=Null) return result;
}
if ( @@[T->NextSibling!=NULL && X>=T->NextSibling->Element ](3)){
result= RecurFindInTree(T->NextSibling, X);
return result;
}
}

```





答案:
第1空:j *= 2

第2空:X>=T->Element

第3空:T->NextSibling!=NULL && X>=T->NextSibling->Element

发表评论

访客

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