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

程序填空题:二叉排序树查找

Luz4年前 (2021-05-10)题库1464
```c++
#include
using namespace std;

typedef struct ElemType{
int key;
}ElemType;

typedef struct BSTNode{
ElemType data;
BSTNode *lchild,*rchild;
}BSTNode,*BSTree;

int flag=1;

BSTree SearchBST(BSTree T,char key) {
if(@@[(!T)|| key==T->data.key](2)) return T;
else if (keydata.key) @@[return SearchBST(T->lchild,key)](2);
else @@[return SearchBST(T->rchild,key)](2);
}

void InsertBST(BSTree &T,ElemType e );//实现细节隐藏

void CreateBST(BSTree &T ) {
int i=1,n;
cin >> n;
T=NULL;
ElemType e;
while(i<=n){
cin>>e.key;
InsertBST(T, e);
i++;
}
}

int main()
{
BSTree T;
CreateBST(T);
int key;
cin>>key;
BSTree result=SearchBST(T,key);
if(result)
{cout<<"find!";}
else
{cout<<"not find!";}
return 0;
}

```






答案:
第1空:(!T)|| key==T->data.key

第2空:return SearchBST(T->lchild,key)

第3空:return SearchBST(T->rchild,key)

发表评论

访客

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