天天酷跑 刷积分 漏洞:能不能请大虾们帮我看下这个程序

来源:百度文库 编辑:高校问答 时间:2024/04/28 11:09:49
题目:假设以二叉树链表作为存储结构,请编写一个在二叉树中删除所有以结点x(x为结点元素值)为根的子树并以某种形式(自定)输出被删除子树的结构的算法
#include<stdio.h>
#define NULL 0
typedef struct bitree{
;
DataType data;
int x;
struct lnode *lchild,*rchild;
}bitree,*Bt;
CreateBitree(Bt t)
{char ch;
scanf("%c",&ch);
if(ch=='#')b=NULL;
else
{if(!(t=(bitree *)malloc(sizeof(bitree)))) exit(OVERFLOW);
t->data=ch;
CreateBitree(t->lchild);
CreateBitree(t->rchild);
}
}
bitree *delsubtree(bitree *b,int x)
{bitree *s;
if(b!=NULL)
if(b->data==x)
{print(b);
s=NULL;
}
else s=finddel(b,x);
return(s);
}
bitree *finddel(bitree *p,int x)
{ bitree *s;
if(p!=NULL)
{if(p->lchild!=NULL&&p->lchild.data==x)
{print(p->lchild);
p->lchild=NULL;
}
if(p->rchild!=NULL&&p->rchild.data==x)
{print(p->rchild);
p->rchild=NULL;
}
s=finddel(p->lchild,x);
p->lchild=s;
s=finddel(p->rchild,x);
p->rchild=s;
}
return(p);
}
void print(bitree *b)
{if(b!=NULL)
{printf("%d",b->data);
if(b->lchild!=NULL||b->rchild!=NULL)
{printf("(");
print(b->lchild);
if(b->rchild!=NULL) printf(",");
print(b->right);
printf(")");
}
}
}
void main()
{CreateBitree(b);
delsubtree(p,x);
}