【5 树与二叉树】查找二叉排序树上的x结点。

typedef struct BSTNode{
	int key;
	struct BSTNode *lchild,*rchild;
}BSTNode,BSTree;

BSTree find_x(BSTree T,int x){
	BSTNode *p=T;
	while(p){
		if(x==p->key)
			return p;
		else if(xkey)
			p=p->lchild;
		else
			p=p->rchild;
	}
	return null;
} 
BSTree find_x(BSTree T,int x){
	if(T==null)
		return null;
	if(x==T->key)
		return T;
	else(xkey)
		find_x(T->lchild,x);
	else
		find_x(T->rchild,x);
}

非递归和递归两种表达。

你可能感兴趣的:(5,树与二叉树,java,数据结构,算法)