#include <stdio.h>
#include <stdlib.h>
typedef struct Bitree {
char data;
struct Bitree* Lchild;
struct Bitree* Rchild;
}Bitree, * Pbitree;
void create(Pbitree* tree) {
char data;
scanf("%c", &data);
getchar();
if (data == '#') {
*tree = NULL;
}
else
{
*tree = (Pbitree)malloc(sizeof(Bitree));
(*tree)->data = data;
create(&(*tree)->Lchild);
create(&(*tree)->Rchild);
}
}
int preorder(Pbitree tree) {
if (tree == NULL) {
return 0;
}
else
{
printf("%c", tree->data);
preorder(tree->Lchild);
preorder(tree->Rchild);
}
}
int inorder(Pbitree tree) {
if (tree == NULL) {
return 0;
}
else
{
inorder(tree->Lchild);
printf("%c", tree->data);
inorder(tree->Rchild);
}
}
int postorder(Pbitree tree) {
if (tree == NULL) {
return 0;
}
else
{
postorder(tree->Lchild);
postorder(tree->Rchild);
printf("%c", tree->data);
}
}
int main() {
Pbitree tree;
create(&tree);
preorder(tree);
printf("\n");
inorder(tree);
printf("\n");
postorder(tree);
return 0;
}