#include
#include
struct tree
{
char info;
struct tree *left;
struct tree *right;
};
struct tree *root;
struct tree *stree(struct tree *root,struct tree *r,char info);
void print_tree(struct tree *root,int l);
int main(void)
{
char s[80];
int l=3;
root=NULL;
do
{
printf("enter a letter:");
gets(s);
root=stree(root,root, *s);
}
while(\*s);
print\_tree(root,0);
return 0;
}
struct tree *stree(struct tree *root,struct tree *r,char info)
{
if(!r)
{
r=(struct tree *) malloc(sizeof(struct tree));
if(!r)
{
printf("out of memory \n");
exit(0);
}
r->left=NULL;
r->right=NULL;
r->info=info;
if(!root)
return r;
if(infoinfo)
root->left=r;
else
root->right=r;
return r;
}
if(infoinfo)
stree(r,r->left,info);
else
stree(r,r->right,info);
return root;
}
void print_tree(struct tree *r,int l)
{
int i;
if(!r) return ;
print_tree(r->right,l+1);
for(i=0;iinfo);
print_tree(r->left,l+1);
}