关于二叉树的问题
#include<stdio.h>#include<stdlib.h>
#include<string.h>
typedef char TElemType;
typedef struct BiTNode
{
TElemType data;
struct BiTNode *Lchild;
struct BiTNode *Rchild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree &root)
{
char ch;
ch=getchar();
if(ch=='#') root=NULL;
else
{
root=(BiTree)malloc(sizeof(BiTNode));
root->data=ch;
CreateBiTree(root->Lchild);
CreateBiTree(root->Rchild);
}
}
void PreOrder(BiTree &root)
{
if(root!=NULL)
{
printf("%c",root->data);
PreOrder(root->Lchild);
PreOrder(root->Rchild);
}
}
void InOrder(BiTree &root)
{
if(root!=NULL)
{
InOrder(root->Lchild);
printf("%c",root->data);
InOrder(root->Lchild);
}
}
void PostOrder(BiTree &root)
{
if(root!=NULL)
{
PostOrder(root->Lchild);
PostOrder(root->Rchild);
printf("%c",root->data);
}
}
int leaf(BiTree &root)
{
int LeafCount;
if(root==NULL)
LeafCount=0;
else if((root->Lchild==NULL)&&(root->Rchild==NULL))
LeafCount=1;
else
LeafCount=leaf(root->Lchild)+leaf(root->Rchild);
return LeafCount;
}
void main()
{
BiTree T;
int a,b;
scanf("%s",&T);
CreateBiTree(T);
printf("先序遍历:1");
printf("中序遍历:2");
printf("后序遍历:3");
printf("叶子结点总数:4");
printf("退出:0");
scanf("%d",&a);
while(a!=0)
{
switch(a)
{
case 1:PreOrder(T);
printf("\n");
break;
case 2:InOrder(T);
printf("\n");
break;
case 3:PostOrder(T);
printf("\n");
break;
case 4:printf("叶子结点总数为:");
b=leaf(T);
printf("%d",b);
printf("\n");
default:printf("error\n");
}
printf("先序遍历:1");
printf("中序遍历:2");
printf("后序遍历:3");
printf("叶子结点总数:4");
printf("退出:0");
scanf("%d",&a);
}
}
在输入的时候为什么输入不进去?