#include <stdio.h>
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
typedef struct st
{
char data;
struct st*l,*r;
}tree;
char ch[50];
int i;
tree*create()
{
tree *t;
if(ch[++i] == ',')
t=NULL;
else
{
t=(st*)malloc(sizeof(st));
t->data=ch[i];
t->l=create();
t->r=create();
}
return t;
}
void zhong(tree *t)
{
if(t)
{
zhong(t->l);
cout<<t->data;
zhong(t->r);
}
}
void hou(tree *t)
{
if(t)
{
hou(t->l);
hou(t->r);
cout<<t->data;
}
}
int main()
{
while(cin>>ch)
{
i=-1;
tree *t;
t=create();
zhong(t);
printf("\n");
hou(t);
cout<<endl;
}
return 0;
}
树的遍历
最新推荐文章于 2023-03-14 17:04:32 发布