注意:此页面搜索的是所有试题
题目内容
(数据结构国家开放大学)
以下函数是二叉排序树的查找算法,若二叉树为空,则返回根结点的指针,否则,返回值是指向树结点的结构指针p(查找成功p指向查到的树结点,不成功p指向为NULL)完成程序中的空格
typedef struct Bnode
{ int key;
struct Bnode *left;
struct Bnode *right;
} Bnode;
Bnode *BSearch(Bnode *bt, int k)
/* bt用于接收二叉排序树的根结点的指针,k用以接收要查找的关键字*/
{ Bnode *p;
if(bt== __(1)__)
return (bt);
p=bt;
while(p->key!= __(2)__)
{ if(k<p->key)
__(3)__;
else __(4)__;
if(p==NULL) break;
}
return(__(5)__;
}
typedef struct Bnode
{ int key;
struct Bnode *left;
struct Bnode *right;
} Bnode;
Bnode *BSearch(Bnode *bt, int k)
/* bt用于接收二叉排序树的根结点的指针,k用以接收要查找的关键字*/
{ Bnode *p;
if(bt== __(1)__)
return (bt);
p=bt;
while(p->key!= __(2)__)
{ if(k<p->key)
__(3)__;
else __(4)__;
if(p==NULL) break;
}
return(__(5)__;
}
参考答案

