程序填空题:二叉排序树查找
```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)
#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 (key
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)