Tempfile.exe停止工作,C语言高手帮帮忙啊

[复制链接]
查看11 | 回复1 | 2010-6-11 12:06:16 | 显示全部楼层 |阅读模式
我用递归方法来求树的节点树,叶子数以及有两个孩子的节点数,但每次运行输入数据后都是Tempfile.exe.停止工作,怎么回事啊。
#include
#include
typedef struct bt
{
char data;
struct bt *Lchild,*Rchild;
}bt;
bt* Creattree(bt *t)
{char ch;
ch=getchar();
getchar();
if(ch=='.')
t=NULL;
else
{t=(bt*)malloc(sizeof(bt));
t->data=ch;
t->Lchild=Creattree(t->Lchild);
t->Rchild=Creattree(t->Rchild);
}
return t;
}
int countnode(bt *t)
{
int count=0;
if(t=NULL)
return 0;
else
{
count++;
count=count+countnode(t->Lchild);
count=count+countnode(t->Rchild);
return count;
}

}
int countleaves(bt *t)
{
int count=0;
if(t=NULL)
return 0;
if(t->Lchild==NULL && t->Rchild==NULL)
return 1;
else
{
count+=countleaves(t->Lchild);

count+=countleaves(t->Rchild);

return count;
}
}
int countTnode(bt *t)
{
int count=0;
if(t=NULL)
return 0;
if(t->Lchild!=NULL && t->Rchild!=NULL)
count=1;
count+=countTnode(t->Lchild);
count+=countTnode(t->Rchild);
return count;
}
void main()
{
bt *t=NULL;
int a, b, c;
printf("建立二叉树:");
t=Creattree(t);
a=countnode(t);
printf("节点数:%d\n",a);
b=countleaves(t);
printf("叶子数:%d\n",b);
c=countTnode(t);
printf("有两个孩子的节点数:%d\n",c);


}

回复

使用道具 举报

千问 | 2010-6-11 12:06:16 | 显示全部楼层
if(t=NULL) << 应该是if(t==NULL),有3处,记得都改过来
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行