函数f33的参数t指向下图所示的二叉排序树的根,阅读程序,回答下列问题。
typedef int KeyType;
typedef struct node{
KeyType key;
node *lchild,*rchild;
}BSTNode,*BSTree;
BSTree f33(BSTree t,KeyType K1,KeyType K2)
{BSTree p;
while(t!=NULL)
{if(t-> key> =K1&&t-> key<=K2)return t;
if(t-> key<K1)
t=t-> rchild;
else
t=t-> lchild;
}
return NULL;
}
(1)写出调用函数f33(t,30,45)后的返回值。
(2)说明函数f33的功能。
【正确答案】:(1)返回指向关键字为40的结点的指针。
(2)在二叉排序树上查找树中离根最近的位于两个关键字之间的值key(K1≤key≤K2)所在结点的指针。如果没有满足条件的结点,返回空指针。