2016最新广工anyview数据结构答案

2026/4/24 10:00:27

} /**********

【题目】编写递归算法,将二叉树中所有结点的 左、右子树相互交换。 二叉链表类型定义: 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)


2016最新广工anyview数据结构答案.doc 将本文的Word文档下载到电脑
搜索更多关于: 2016最新广工anyview数据结构答案 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219