建的这个数不能实现啊哪位高手给我点建议直接建个树而不是自己输入元素让人系统自己建
#include<stdio.h>#include<stdlib.h>
#define MAXSIZE 20
typedef struct BiTnode{
char data;
struct BiTnode *lchild,*rchild;
}BiTnode,*BiTree;
int i=0;
void display(BiTree t)
{
BiTree stack[MAXSIZE],p;
int top=-1;
if(t)
{
p=t;
while(top>-1||p)
{
while(p)
{
stack[++top]=p;
p=p->lchild;
}
if(top>-1)
{
p=stack[top--];
printf("%c ",p->data);
p=p->rchild;
}
}
printf("\n");
}
}
void play(BiTree t)
{
if(t)
{
play(t->lchild);
printf("%c ",t->data);
play(t->rchild);
}
}
void asplay(BiTree t)
{
if(t)
{
printf("%c ",t->data);
asplay(t->lchild);
asplay(t->rchild);
}
}
BiTree Create(BiTree t)
{
char s[]="abc de f g ";
char ch;
ch=s[i++];
if(ch==' ')
{
t=NULL;
}
else
{
if(!(t=(BiTree)malloc(sizeof(BiTree))))
{
printf("The malloc is fail!");
exit(0);
}
else
{
t->data=ch;
t->lchild=Create(t->lchild);
t->rchild=Create(t->rchild);
}
}
return t;
}
int main()
{
BiTree t;
t=Create(t);
display(t);
play(t);
printf("\n");
asplay(t);
return 0;
}