# Include <stdio. h>
# Include <alloc. h>
# Include <conio. h>
# Deprecision MAX 100
Typedef struct tnode
{
Int data;
Struct tnode * lchild, * rchild;
} TNODE;
Void create ();
Void insert (int);/* insert node */
Void inorder (TNODE *);/* sequential traversal */
TNODE * root = NULL;
Void main ()
{
Clrscr ();
Create ();
Inorder (root );
}
Void inorder (TNODE * ptr)
{
If (ptr! = NULL)
{
Inorder (
Ptr-> lchild );
Printf ("% d", ptr-> data );
Inorder (ptr-> rchild );
}
}
Void create ()
{
Int n, I;
Int k [MAX];
Printf ("please input the node number :");
Scanf ("% d", & n );
For (I = 0; I <n; I ++)
Scanf ("% d", & k [I]);
For (I = 0; I <n; I ++)
Insert (k [I]);
}
Void insert (int m)
{
TNODE * p1, * p2;
If (root = NULL)
{
Root = (TNODE *) malloc (sizeof (TNODE ));
Root-> data = m;
Root-> lchild = root-> rchild = NULL;
}
Else
{
P1 = root;
While (m! = P1-> data)
{
If (m <p1-> data) & (p1-> lchild! = NULL) p1 = p1-> lchild;
Else if (m> p1-> data) & (p1-> rchild! = NULL) p1 = p1-> rchild;
Else if (m <p1-> data) & (p1-> lchild = NULL ))
{
P2 = (TNODE *) malloc (sizeof (TNODE ));
P2-> data = m;
P2-> lchild = p2-> rchild = NULL;
P1-> lchild = p2;
Return;
}
Else if (m> p1-> data) & (p
<