当前位置:首页 > 2016最新广工anyview数据结构答案
/* 对于二叉树T中每一个元素值为x的结点, */ /* 删去以它为根的子树,并释放相应的空间 */ {
if(T==NULL)return ; if(T->data==x) {
ReleaseX(T->rchild,T->rchild->data); ReleaseX(T->lchild,T->lchild->data);free(T); } else {
ReleaseX(T->rchild,x); ReleaseX(T->lchild,x); } } /**********
【题目】编写复制一棵二叉树的递归算法。
二叉链表类型定义:
typedef char TElemType; // 设二叉树的元素为char类型 typedef struct BiTNode { TElemType data;
struct BiTNode *lchild, *rchild; } BiTNode, *BiTree; **********/
void CopyBiTree(BiTree T, BiTree &TT) /* 递归复制二叉树T得到TT */ {
if(T==NULL){TT=NULL;return;} TT=(BiTree)malloc(sizeof(BiTNode)); TT->data=T->data; if(T->lchild!=NULL){
TT->lchild=(BiTree)malloc(sizeof(BiTNode));
CopyBiTree(T->lchild, TT->lchild);} if(T->rchild!=NULL){
TT->rchild=(BiTree)malloc(sizeof(BiTNode)); CopyBiTree(T->rchild, TT->rchild); } } /**********
【题目】编写算法判别给定二叉树是否为完全二叉树。 二叉链表类型定义: typedef struct BiTNode { TElemType data;
struct BiTNode *lchild, *rchild; } BiTNode, *BiTree;
可用队列类型Queue的相关定义:
typedef BiTree QElemType; // 设队列元素为二叉树的指针类型
Status InitQueue(Queue &Q);
Status EnQueue(Queue &Q, QElemType e); Status DeQueue(Queue &Q, QElemType &e); Status GetHead(Queue Q, QElemType &e); Status QueueEmpty(Queue Q); **********/
Status CompleteBiTree(BiTree T) /* 判别二叉树T是否为完全二叉树 */ {
Queue q;int i=0; InitQueue (q);
if(T==NULL)return TRUE; EnQueue(q,T);
共分享92篇相关文档