为什么二插树的复制,等都是0?
#include<stdio.h>#include<stdlib.h>
typedef struct BiTone{
char ch;
struct BiTone *lchild,*rchild;
}BiTone;
void CreateBiTone(BiTone *T){
int i,cha;
//static int a=1;
printf("请输入要储存的值:");
cha=getchar();
while((i=getchar())!='\n' && i!=EOF);
if(cha=='#'){
T=NULL;
}else{
T=malloc(sizeof(BiTone));
if(NULL==T){
printf("申请失败");
exit(1);
}
T->ch=cha;
//printf();
printf("目前创建左子树\n");
CreateBiTone(T->lchild);
printf("目前储存的是右子树\n");
CreateBiTone(T->rchild);
}
}
void Copy(BiTone *T,BiTone *t){
if(NULL==T){
t=NULL;
return;
}else{
t=malloc(sizeof(BiTone));
if(NULL==t){
printf("申请失败");
exit(1);
}
t->ch=T->ch;
Copy(T->lchild,t->lchild);
Copy(T->rchild,t->rchild);
}
}
int Nodecount(BiTone *T){
if(NULL==T){
return 0;
}else{
return Nodecount(T->lchild)+Nodecount(T->rchild)+1;
}
}
int Depth(BiTone *T){
int l,r;
if(NULL==T){
return 0;
}else{
l=Depth(T->lchild);
r=Depth(T->rchild);
if(l>r)
return l+1;
else
return r+1;
}
}
int main(){
BiTone *T=NULL,*t=NULL;
CreateBiTone(T);
printf("创建成功\n");
printf("%p",T);
Copy(T,t);
printf("复制成功\n");
printf("%d\n",Depth(T));
printf("%d\n",Depth(t));
printf("%d\n",Nodecount(T));
printf("%d\n",Nodecount(T));
}