#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
typedef struct treeNode
{
char data;
struct treeNode *left;
struct treeNode *right;
} treeNode;
treeNode* makeRoodNode(char data, treeNode* leftNode, treeNode* rightNode)
{
treeNode* root = (treeNode *)malloc(sizeof(treeNode));
root -> data = data;
root->left = leftNode;
root -> right = rightNode;
return root;
}
void preorder(treeNode* root)
{
if(root)
{
printf("%c",root->data);
preorder(root->left);
preorder(root->right);
}
}
void inorder(treeNode* root)
{
if(root)
{
inorder(root->left);
printf("%c",root->data);
inorder(root->right);
}
}
void lastorder(treeNode* root)
{
if(root)
{
lastorder(root->left);
lastorder(root->right);
printf("%c",root->data);
}
}
void main()
{
treeNode* n7 = makeRoodNode('D',NULL,NULL);
treeNode* n6 = makeRoodNode('C',NULL,NULL);
treeNode* n5 = makeRoodNode('B',NULL,NULL);
treeNode* n4 = makeRoodNode('A',NULL,NULL);
treeNode* n3 = makeRoodNode('/',n6,n7);
treeNode* n2 = makeRoodNode('*',n4,n5);
treeNode* n1 = makeRoodNode('-',n2,n3);
printf("\n preorder : ");
preorder(n1);
printf("\n inorder : ");
inorder(n1);
printf("\n lastorder : ");
lastorder(n1);
getchar();
}