[Cpp]
// File name: exp7-1.cpp
# Include <stdio. h>
Typedef char ElemType;
Typedef struct node
{
ElemType data; // data Element
Struct node * lchild; // point to left child
Struct node * rchild; // point to the right child
} BTNode;
Extern void CreateBTNode (BTNode * & B, char * str );
Extern BTNode * FindNode (BTNode * B, ElemType x );
Extern BTNode * LchildNode (BTNode * p );
Extern BTNode * RchildNode (BTNode * p );
Extern int BTNodeDepth (BTNode * B );
Extern void DispBTNode (BTNode * B );
Extern int BTWidth (BTNode * B );
Extern int Nodes (BTNode * B );
Extern int LeafNodes (BTNode * B );
Extern void DestroyBTNode (BTNode * & B );
Int main ()
{BTNode * B, * p, * lp, * rp ;;
CreateBTNode (B, "A (B (D, E (H (J, K (L, M (, N), C (F, G (, I )))");
Printf ("basic binary tree operation: \ n ");
Printf ("(1) output binary tree:"); DispBTNode (B); printf ("\ n ");
Printf ("(2) H node :");
P = FindNode (B, 'H ');
If (p! = NULL)
{Lp = LchildNode (p );
If (lp! = NULL)
Printf ("% c for left children", lp-> data );
Else
Printf ("No left child ");
Rp = RchildNode (p );
If (rp! = NULL)
Printf ("% c for the right child", rp-> data );
Else
Printf ("no right child ");
}
Printf ("\ n ");
Printf ("(3) Depth of Binary Tree B: % d \ n", BTNodeDepth (B ));
Printf ("(4) width of Binary Tree B: % d \ n", BTWidth (B ));
Printf ("(5) number of Nodes of Binary Tree B: % d \ n", Nodes (B ));
Printf ("(6) Number of leaf nodes of Binary Tree B: % d \ n", LeafNodes (B ));
Printf ("(7) Release Binary Tree B \ n ");
DestroyBTNode (B );
}
// File name: exp7-1.cpp
# Include <stdio. h>
Typedef char ElemType;
Typedef struct node
{
ElemType data; // data Element
Struct node * lchild; // point to left child
Struct node * rchild; // point to the right child
} BTNode;
Extern void CreateBTNode (BTNode * & B, char * str );
Extern BTNode * FindNode (BTNode * B, ElemType x );
Extern BTNode * LchildNode (BTNode * p );
Extern BTNode * RchildNode (BTNode * p );
Extern int BTNodeDepth (BTNode * B );
Extern void DispBTNode (BTNode * B );
Extern int BTWidth (BTNode * B );
Extern int Nodes (BTNode * B );
Extern int LeafNodes (BTNode * B );
Extern void DestroyBTNode (BTNode * & B );
Int main ()
{BTNode * B, * p, * lp, * rp ;;
CreateBTNode (B, "A (B (D, E (H (J, K (L, M (, N), C (F, G (, I )))");
Printf ("basic binary tree operation: \ n ");
Printf ("(1) output binary tree:"); DispBTNode (B); printf ("\ n ");
Printf ("(2) H node :");
P = FindNode (B, 'H ');
If (p! = NULL)
{Lp = LchildNode (p );
If (lp! = NULL)
Printf ("% c for left children", lp-> data );
Else
Printf ("No left child ");
Rp = RchildNode (p );
If (rp! = NULL)
Printf ("% c for the right child", rp-> data );
Else
Printf ("no right child ");
}
Printf ("\ n ");
Printf ("(3) Depth of Binary Tree B: % d \ n", BTNodeDepth (B ));
Printf ("(4) width of Binary Tree B: % d \ n", BTWidth (B ));
Printf ("(5) number of Nodes of Binary Tree B: % d \ n", Nodes (B ));
Printf ("(6) Number of leaf nodes of Binary Tree B: % d \ n", LeafNodes (B ));
Printf ("(7) Release Binary Tree B \ n ");
DestroyBTNode (B );
}