# Include <stdlib. h>
# Include <stdio. h>
# Define MAX 50
# Define MAS 20
# Define CHAR 1
# If CHAR
Typedef char TElemType;
TElemType Nil = '';
# Define form "% c"
# Else
Typedef int TElemType;
TElemType Nil = 0;
# Define form "% d"
# Endif
Typedef struct node
{TElemType data;
Struct node * left;
Struct node * right;
Struct node * parent;
} BiTNode, * BiTree;
BiTNode * InitBiTree (BiTNode * bt)
{
Bt = NULL;
Return bt;
}
BiTNode * CreateBiTree (BiTNode * bt)
{TElemType ch;
Scanf (form, & ch );
If (ch = Nil) bt = NULL;
Else
{Bt = (BiTNode *) malloc (sizeof (BiTNode ));
If (! Bt) exit (0 );
Bt-> data = ch; bt-> parent = NULL;
Bt-> left = CreateBiTree (bt-> left );
If (bt-> left) bt-> left-> parent = bt;
Bt-> right = CreateBiTree (bt-> right );
If (bt-> right) bt-> right-> parent = bt;
}
Return bt;
}
Void PrintTree (BiTNode * bt, int I)
{If (bt! = NULL)
{PrintTree (bt-> right, I + 5 );
# If CHAR
If (bt-> data! = Nil)
Printf ("% * cn", I, bt-> data );
# Else
If (bt-> data! = Nil)
Printf ("% * dn", I, bt-> data );
# Endif
PrintTree (bt-> left, I + 5 );
I = I-5;
}
}
Void Prorder1 (BiTNode * bt, void (* visit) (TElemType)/* sequential traversal */
{If (bt! = NULL)
{Visit (bt-> data );
Prorder1 (bt-> left, visit );
Prorder1 (bt-> right, visit );
}
}
Void Prorder2 (BiTNode * bt, void (* visit) (TElemType)/* sequential traversal */
{BiTNode * p, * stack [MAS];
Int top;
Top = 0; p = bt;
While (top! = 0 | p! = NULL)
{While (p! = NULL)
{Stack [top] = p; top ++;
P = p-> left;
}
If (top! = 0)
{P = stack [top-1];
Top --;
Visit (p-> data );
P = p-> right;
}
}
}
Void Prorder3 (BiTNode * bt, void (* visit) (TElemType)/* post-sequential traversal */
{BiTNode * p,