Tree
Tree
h>
#include<stdlib.h>
struct node
{
char info;
struct node *lchild;
struct node *rchild;
};
node *root;
int tag=0;
void inorder(node *);
void preorder(node *);
void postorder(node *);
void create(node *);
node *getnode();
int main()
{
int ch;
do
{
if (tag==0)
{
printf("\n Enter the root node ");
root=getnode();
create(root);
tag=1;
ch=0;
}
else
{
printf("\n 1. Inorder");
printf("\n 1. Preoder");
printf("\n 1. Postorder");
printf("\n 1. Enter your choice");
fflush(stdin);
scanf("%d",&ch);
switch(ch)
{
case 1:
inorder(root);
break;
case 2:
preorder(root);
break;
case 3:
postorder(root);
break;
case 4:
break;
}
}
} while(ch!=4);
return 0;
}
node *getnode()
{
node *t;
t=(node*)malloc(sizeof(node));
fflush(stdin);
scanf("%c",&t->info);
t->lchild=NULL;
t->rchild=NULL;
return(t);
}