# Include <stdio. h>
# Include <stdlib. h>
# Define MAXSIZE 20
Typedef struct BiTnode {
Char data;
Struct BiTnode * lchild, * rchild;
} BiTnode, * BiTree;
// You can see the following:
Int I = 0;
BiTree Create (BiTree t, char s [])
{
Char ch;
Ch = s [I ++];
If (ch = '')
{
T = NULL;
}
Else
{
If (! (T = (BiTree) malloc (sizeof (BiTnode ))))
{
Printf ("fail to malloc! \ N ");
Exit (0 );
}
Else
{
T-> data = ch;
T-> lchild = Create (t-> lchild, s );
T-> rchild = Create (t-> rchild, s );
}
}
Return t;
}
// A few clicks
/*
Void display (BiTree t)
{
BiTree stack [MAXSIZE], p;
Int top =-1;
If (t)
{
P = t;
While (top>-1 | p)
{
While (p)
{
Stack [++ top] = p;
P = p-> lchild;
}
If (top>-1)
{
P = stack [top --];
Printf ("% c", p-> data );
P = p-> rchild;
}
}
Printf ("\ n ");
}
}
/*/
// Please wait until then
/*
Void display (BiTree t)
{
BiTree stack [MAXSIZE], p;
Int top =-1;
If (t)
{
P = t;
While (top>-1 | p)
{
While (p)
{
Printf ("% c", p-> data );
Stack [++ top] = p;
P = p-> lchild;
}
If (top>-1)
{
P = stack [top --];
P = p-> rchild;
}
}
Printf ("\ n ");
}
}
*//*
// Please wait until then
Void display (BiTree t)
{
BiTree stack [MAXSIZE], p;
Int top =-1;
If (t)
{
Stack [++ top] = t;
While (top>-1)
{
P = stack [top --];
Printf ("% c", p-> data );
If (p-> rchild)
{
Stack [++ top] = p-> rchild;
}
If (p-> lchild)
{
Stack [++ top] = p-> lchild;
}
}
Printf ("\ n ");
}
}*/
/*
// Assume that the parameter is € ;{{}}}}}}}
Void display (BiTree t)
{
BiTree m, stack [MAXSIZE];
Int top =-1;
Int flag;
If (t)
{
Loop:
Flag = 1;
M = NULL;
While (t)
{
Stack [++ top] = t;
T = t-> lchild;
}
While (flag)
{
T = stack [top];
If (t-> rchild = m)
{
Printf ("% c", t-> data );
Top --;
M = t;
}
Else
{
Flag = 0;
T = t-> rchild;
}
}
If (top>-1)
Goto loop;
}
Printf ("\ n ");
}
*/
// Assume that the parameter is € ;{{}}}}}}}
Void display (BiTree t)
{
BiTree p = t, stack [MAXSIZE];
Int tag [MAXSIZE];
Int top =-1;
Do
{
While (p! = NULL)
{
Stack [++ top] = p;
Tag [top] = 0;
P = p-> lchild;
}
If (top>-1)
{
If (! Tag [top])
{
P = stack [top];
P = p-> rchild;
Tag [top] = 1;
}
Else
{
Printf ("% c", stack [top --]-> data );
}
}
} While (p! = NULL) | (top>-1 ));
Printf ("\ n ");
}
// When there are too many threads, there are too many threads
/* Void display (BiTree t)
{
If (t)
{
Printf ("% c", t-> data );
Display (t-> lchild );
Display (t-> rchild) tables?
}
}*/
// Please try again
/* Void display (BiTree t)
{
If (t)
{
Display (t-> lchild );
Printf ("% c", t-> data );
Display (t-> rchild) tables?
}
}*/
// When there are too many threads, there are too many threads
/* Void display (BiTree t)
{
If (t)
{
Display (t-> lchild );
Display (t-> rchild );
Printf ("% c", t-> data );
}
}*/
Int main (int argc, char * argv [])
{
BiTree t;
Char s [] = "abc de f g ";
T = Create (t, s );
Display (t );
Return 0;
}