Quote:
ok i changed it and fixed the curly brackets
Warning: Spoiler! (Click to show)Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
typedef struct tree*node;
node insert(int,node T);
void inorder(node T);
void preorder(node T);
void postorder(node T);
struct tree
{
int data;
struct tree*right,*left;
}*root;
int main()
{
node T= NULL;
int data,ch,i=0,n;
clrscr();
printf("\nEnter the number of elements in the Tree:");
scanf("%d",&n);
printf("\n The elements are :\n");
while(i<n);
{
scanf("%d",&data);
T=insert(data,T);
i++;
}
printf("1. INORDER\t2.PREORDER\t3.POSTOTRDER\t4.EXIT");
do
{
printf("\nEnter your choide:");
scanf("%d",&ch);
switch (ch)
{
case1: printf ("Inorder traversal of the given Tree\n");
inorder(T);
break;
case2: printf("Preoroder traversal of the given Tree\n");
preorder(T);
break;
case3: printf("Postorder traversal of the given Tree\n");
posotorder(T);
break;
default:printf("Exit");
exit(0);
}
}
while(ch<4);
getch();
node insert(intX, node T)
{
struct tree*newnode;
newnode=malloc(sizeof(struct tree));
if(newnode==NULL)
printf("Out of space\n");
else
{
if(T==NULL)
{
newnode->data=X;
newnode->left=NULL;
newnode->right=NULL;
T=newnode;
}
else
{
if(X<T->data)
T->left=insert(X,T->left);
else
T->right=insert(X,T->right);
}
}
return T;
}
void inorder(node T)
{
if(T!=NULL)
{
inorder(T->left);
printf("%d\t",T->ddata);
inorder(T->right);
}
}
void preorder(node T)
{
if(T!=NULL)
{
printf("%d\t",T->data);
preorder(T->left);
preorder(T->right);
}
}
void postoroder(node T)
{
if(T!=NULL);
{
postorder(T->left);
postorder(T->right);
printf("%d\t",T->data);
}
}
}






