当前位置:首页 > 2016最新广工anyview数据结构答案
} /**********
【题目】编写递归算法,将二叉树中所有结点的 左、右子树相互交换。 二叉链表类型定义: typedef struct BiTNode { TElemType data;
struct BiTNode *lchild, *rchild; } BiTNode, *BiTree; **********/
void ExchangeSubTree(BiTree &T)
/* 将二叉树中所有结点的左、右子树相互交换 */ {
BiTree p=T, temp; if(p){
temp=p->lchild; p->lchild=p->rchild; p->rchild=temp; } else return ;
ExchangeSubTree(p->lchild); ExchangeSubTree(p->rchild); } /**********
【题目】编写递归算法:求二叉树中以元素值 为x的结点为根的子树的深度。 二叉链表类型定义: typedef struct BiTNode { TElemType data;
struct BiTNode *lchild, *rchild; } BiTNode, *BiTree; **********/
int Depthx(BiTree T, TElemType x)
/* 求二叉树中以值为x的结点为根的子树深度 */ {
int i=0,i1,i2;
if(T==NULL)return 0; if(T->data==x) {
i1=1+Depthx(T->rchild,T->rchild->data); i2=1+Depthx(T->lchild,T->lchild->data); return i1>i2?i1:i2; } else {
i1=Depthx(T->rchild,x);
i2=Depthx(T->lchild,x); return i1>i2?i1:i2; } } /**********
【题目】编写递归算法:对于二叉树中每一个元素值为x 的结点,删去以它为根的子树,并释放相应的空间。 二叉链表类型定义: typedef struct BiTNode { TElemType data;
struct BiTNode *lchild, *rchild; } BiTNode, *B iTree; **********/
void ReleaseX(BiTree &T, char x)
共分享92篇相关文档