求助!关于统计二叉树非叶子节点。我编写的可以运行但不能嵌套在switch()上
我是要在switch()上添加几个模块的,但是发现统计二叉树这模块不行。这算法不能加在条件语句上,if语句我也试过,不行
但是我单独运行它,又是可以的。不知道为什么。希望大家帮帮忙
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
typedef struct node{
char data;
struct node *lchild,*rchild;
}bitnode,*bitree;/*二叉树结点结构定义*/
bitree creatbitree()
{
bitree T;
char ch;
scanf("%c",&ch);
if(ch==' ') T=NULL;
else{
if(!(T=(bitnode *)malloc(sizeof(bitnode)))) exit(1);
T->data=ch; /*生成根结点*/
T->lchild=creatbitree(); /*构造左子树*/
T->rchild=creatbitree(); /*构造右子树*/
}
return(T);
}
int count_notleaf(bitree t)
{
if(t==NULL) return(0);
if((t->lchild==NULL)&&(t->rchild==NULL)) return(0);
return(1+count_notleaf(t->lchild)+count_notleaf(t->rchild));
}
void jiedian()
{
int a; bitree T;
printf("please input di gui xun lie \n");
T=creatbitree();
a=count_notleaf(T);
printf("the num of notleaf is %d",a);
printf("\ninput any key to exit and return the front level");
getch();
}
void main()
{
int choose;
while(1)
{
printf("input 1 to tong ji fei ye zi jie dian");
scanf("%d",&choose);
switch(choose)
{
case 1: jiedian();break;
}
}
}