程序填空题:二叉排序树查找的递归算法
本题要求实现二叉排序树的查找操作。
对于二叉排序树,如下图:

### 输入样例:
```
4
1 8 0 9
```
### 输出样例:
```out
1 is found
8 is found
0 is not found
9 is not found
```
其中BSTree结构定义如下:
```
typedef int ElemType;
typedef struct BSTNode
{
ElemType data;
struct BSTNode *lchild,*rchild;
}BSTNode,*BSTree;
```
### 程序如下:
```
#include
#include
typedef int ElemType;
typedef struct BSTNode
{
ElemType data;
struct BSTNode *lchild,*rchild;
}BSTNode,*BSTree;
BSTree CreateBST();/ *二叉排序树创建,由裁判实现,细节不表* /
BSTree SearchBST(BSTree T,ElemType e);
int main()
{
BSTree T,result;
ElemType n,e;
T = CreateBST();
scanf("%d",&n);
for(int i=0;i {
scanf("%d",&e);
result = SearchBST(T,e);
if(result) printf("%d is found\n",result->data);
else printf("%d is not found\n",e);
}
return 0;
}
BSTree SearchBST(BSTree T,ElemType e)
{
if(@@[!T||T->data == e](2)) return T;
if(edata) return @@[ SearchBST(T->lchild,e) ](2);
else @@[ return SearchBST(T->rchild,e) ](2);
}
```
答案:
第1空:!T||T->data == e
第2空: SearchBST(T->lchild,e)
第3空: return SearchBST(T->rchild,e)
对于二叉排序树,如下图:

### 输入样例:
```
4
1 8 0 9
```
### 输出样例:
```out
1 is found
8 is found
0 is not found
9 is not found
```
其中BSTree结构定义如下:
```
typedef int ElemType;
typedef struct BSTNode
{
ElemType data;
struct BSTNode *lchild,*rchild;
}BSTNode,*BSTree;
```
### 程序如下:
```
#include
#include
typedef int ElemType;
typedef struct BSTNode
{
ElemType data;
struct BSTNode *lchild,*rchild;
}BSTNode,*BSTree;
BSTree CreateBST();/ *二叉排序树创建,由裁判实现,细节不表* /
BSTree SearchBST(BSTree T,ElemType e);
int main()
{
BSTree T,result;
ElemType n,e;
T = CreateBST();
scanf("%d",&n);
for(int i=0;i
scanf("%d",&e);
result = SearchBST(T,e);
if(result) printf("%d is found\n",result->data);
else printf("%d is not found\n",e);
}
return 0;
}
BSTree SearchBST(BSTree T,ElemType e)
{
if(@@[!T||T->data == e](2)) return T;
if(e
else @@[ return SearchBST(T->rchild,e) ](2);
}
```
答案:
第1空:!T||T->data == e
第2空: SearchBST(T->lchild,e)
第3空: return SearchBST(T->rchild,e)