void exchange(BiTree bt)//将二叉树 bt 所有结点的左右子树交换{
if(bt){
BiTree s;
s=bt->lchild;
bt->lchild=bt->rchild;
bt->rchild=s; //左右子女交换
exchange(bt->lchild); //交换左子树上所有结点的左右子树
exchange(bt->rchild); //交换右子树上所有结点的左右子树
}
}
bitree findnode(bitree *root, datatype x){// 在二叉树中查找具有给定值的结点
if ( root == NULL) return(NULL);
else if (root ->data == x) return(root );
else return( findnode(root->left,x)||findnode(root->right,x) )
}
int Depth(BitTree T){// 求二叉树的深度
if (!T) depthval = 0;
else{
depthLeft = Depth(T->lchild);
depthRight = Depth(T->rchild);
depthval = 1+(depthLeft >depthRight?depthLeft:depthRight);
}
return depthval;
}
void CountLeaf(BiTree T,int& count){// 统计二叉树中叶子节点的个数( 先序遍历)
if (T){
if ((!T->lchild) && (!T->rchild)) coun++;
CountLeaf(T->lchild,count);
CountLeaf(T->rchild,count);
}
}
BitNode* GetTreeNode(TElemType item,BitNode *lprt,BitNode *rprt){// 复制二叉树
if (!(T=(BitNode*)malloc(sizeof(BitNode)))) return;
T->data=item;
T->lchild = lprt;
T->rchild = rprt;
return T;
}
BitNode* CopyTree(BitNode* T){
if (!T) return NULL;
if (T->lchild) newlprt = CopyTree(T->lchild);
else newlprt = NULL;
if (T->rchild) newrprt = CopyTree(T->rchild);
else newrprt = NULL;
newnode = GetTreeNode(T->data,newlprt,newrprt);
return newnode;