Professional Documents
Culture Documents
Program of B.S.T.
Program of B.S.T.
Program of B.S.T.
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct tree
int head;
//int a[4];
};
int ch1,n,flag=0,in,n=1;
void main()
char ch='y';
r=NULL;
clrscr();
while (ch=='y')
clrscr();
printf("\n 5.Exit");
scanf("%d",&ch1);
switch (ch1)
case 1:
if (insert(&r)==0)
n++;
break;
case 2:
printf("\n\n Left,Root,Right");
inorder(r);
getch();
break;
case 3:
printf("\n \n Root,Left,Right");
preorder(r);
getch();
break;
case 4:
printf("\n\n Left,Right,Root");
postorder(r);
getch();
break;
case 5:
exit();
default :
getch();
} //main close
if (*ptr==NULL)
scanf("%d",&n);
(*ptr)->head=n;
(*ptr)->l=NULL;
(*ptr)->r=NULL;
return(0);
//flag=1;}
else
clrscr();
printf("\n Exit");
scanf("%d",&in);
switch(in)
case 1:
insert(&(*ptr)->l);
break;
case 2:
insert(&(*ptr)->r);
break;
case 3:
break;
default:
}// switch
return(0);
} //fun close
if(ptr!=NULL)
inorder(ptr->l);
printf("%d",ptr->head);
inorder(ptr->r);
} // if close
return(0);
} //fun close
if (ptr!=NULL)
printf("%d",ptr->head);
preorder(ptr->l);
preorder(ptr->r);
} // if close
return(0);
} //fun close
if (ptr!=NULL)
postorder(ptr->l);
postorder(ptr->r);
printf("%d",ptr->head);
} // if close
return(0);
} //fun close