# Include "stdafx. H"
# Include "stdlib. H"
# Include "stdio. H"
Struct tree {
Char Info;
Struct tree * left;
Struct tree * right ;}
;
Struct tree * root;
Void print_tree (struct tree * r, int L );
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 mem ");
Exit (0 );
}
R-> left = NULL;
R-> right = NULL;
R-> info = Info;
If (! Root) return R;
If (info <root-> info)
Root-> left = R;
Else
Root-> right = R;
Return R;
}
If (info <r-> info)
Stree (R, R-> left, Info );
Else
Stree (R, R-> right, Info );
Return root;
}
Int main (void)
{
Char s [80];
Root = NULL;
Do
{
Printf ("enter a letter: \ n ");
Gets (s );
Root = stree (root, root, * s );
}
While (* s );
Print_tree (root, 0 );
Return 0;
}
Void print_tree (struct tree * r, int L)
{
Int I;
If (! R) return;
Print_tree (R-> right, L + 1 );
For (I = 0; I <1; ++ I) printf ("");
Printf ("% C \ n", R-> info );
Print_tree (R-> left, l + 1 );
}
Compiled by vc6.0...