#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef struct node{
char data;
struct node *l,*r;
}tree;
void createTree(tree** T){
char ch;
scanf("%c",&ch);
if(ch==' ') *T = NULL ;
else {
*T = (tree*)malloc(sizeof(tree));
(*T)->data = ch;
createTree(&((*T)->l));
createTree(&((*T)->r));
}
}
void preorder(tree *T){
if(T){
printf("%c ",T->data);
preorder(T->l);
preorder(T->r);
}
}
void inorder(tree *T){
if(T){
inorder(T->l);
printf("%c ",T->data);
inorder(T->r);
}
}
void postorder(tree *T){
if(T){
postorder(T->l);
postorder(T->r);
printf("%c ",T->data);
}
}
int main()
{
tree *T;
createTree(&T);
printf("root = %d\n",T->data);
printf("The preorder:");
preorder(T);
printf("\nThe inorder:");
inorder(T);
printf("\nThe postorder:");
postorder(T);
printf("\n");
system("pause");
return 0;
}
#include<malloc.h>
#include<stdlib.h>
typedef struct node{
char data;
struct node *l,*r;
}tree;
void createTree(tree** T){
char ch;
scanf("%c",&ch);
if(ch==' ') *T = NULL ;
else {
*T = (tree*)malloc(sizeof(tree));
(*T)->data = ch;
createTree(&((*T)->l));
createTree(&((*T)->r));
}
}
void preorder(tree *T){
if(T){
printf("%c ",T->data);
preorder(T->l);
preorder(T->r);
}
}
void inorder(tree *T){
if(T){
inorder(T->l);
printf("%c ",T->data);
inorder(T->r);
}
}
void postorder(tree *T){
if(T){
postorder(T->l);
postorder(T->r);
printf("%c ",T->data);
}
}
int main()
{
tree *T;
createTree(&T);
printf("root = %d\n",T->data);
printf("The preorder:");
preorder(T);
printf("\nThe inorder:");
inorder(T);
printf("\nThe postorder:");
postorder(T);
printf("\n");
system("pause");
return 0;
}