Professional Documents
Culture Documents
h>
#include<conio.h>
struct node
{
char ch;
struct node *left,*right;
}*root=NULL,*p;
void create();
void createlr(struct node *);
void preorder(struct node *);
void inorder(struct node *);
void postorder(struct node *);
void main()
{
clrscr();
create();
printf("\nPreorder Traversal:");
preorder(root);
printf("\nInorder Traversal:");
inorder(root);
printf("\nPostorder Traversal:");
postorder(root);
getch();
}
void create()
{
char c;
printf("Enter the value of root (Enter $ for null)");
fflush(stdin);
scanf("%c",&c);
if(c!='$')
{
p=(struct node *)malloc(sizeof(struct node));
p->ch=c;
p->left=NULL;
p->right=NULL;
root=p;
createlr(root);
}
}