先输入一个字符串 然后求先中后序遍历
http://paste.ubuntu.org.cn/4213378
#include
#include
char w[100];
struct node
{
char data;
struct node *l;
struct node *r;
};
void creat(struct node *&T,char *w)
{
char ch;int p;
ch=*w;
if(ch=='\0') p=1;
if(ch==',') {T=NULL;w++;}
else
{
T=(struct node *)malloc(sizeof(struct node));
T->data=ch;
w++;
// printf("%c",T->data);
creat(T->l,w);
creat(T->r,w);
}
}
void travel(struct node *T)
{
if(T)
{
travel(T->l);
printf("%c",T->data);
travel(T->r);
}
}
void travel2(struct node *T)
{
if(T)
{
travel2(T->l);
travel2(T->r);
printf("%c",T->data);
}
}
void travel3(struct node *T)
{
if(T)
{
printf("%c",T->data);
travel3(T->l);
travel3(T->r);
}
}
int main()
{
struct node *head,*T;
scanf("%s",w);
T=NULL;
creat(T,w);
// printf("%c",head->r->data);
travel3(T);
printf("\n");
travel(T);
printf("\n");
travel2(T);
printf("\n");
}