# Include <malloc. h>
# Include <iostream. h>
# Include <stdio. h>
Int COUNT = 0, high = 0, H1 = 0, H2 = 0;
Struct Node
{
Char data;
Node * leftchild;
Node * rigthchild;
};
Typedef node * btree;
Int Init (btree & BT)
{
Bt = (btree) malloc (sizeof (node ));
If (bt = 0) return 0;
Bt = NULL;
Return 1;
}
/////////////
// DLR create tree
//// // Create a binary tree
Void create (btree & BTR)
{
Char ch;
Cin> CH;
If (CH = '#')
{
BTR = NULL;
Return;
}
Else
{
BTR = (btree) malloc (sizeof (node ));
BTR-> DATA = CH;
Create (BTR-> leftchild );
Create (BTR-> rigthchild );
}
}
// Output tree DLR Binary Tree first Traversal
Void preorder_dlr (btree & root)
{
If (root! = NULL)
{
Cout <root-> data;
Preorder_dlr (root-> leftchild );
Preorder_dlr (root-> rigthchild );
}
}
// Output tree LDR Binary Tree sequential Traversal
Void preorder_ldr (btree & root)
{
If (root! = NULL)
{
Preorder_ldr (root-> leftchild );
Cout <root-> data;
Preorder_ldr (root-> rigthchild );
}
}
// Output tree LRD Binary Tree post-sequential Traversal
Void preorder_lrd (btree & root)
{
If (root! = NULL)
{
Preorder_lrd (root-> leftchild );
Preorder_lrd (root-> rigthchild );
Cout <root-> data;
}
}
// Calculate the number of nodes in a binary tree
Int trav_leaf (btree root)
{
If (root! = NULL)
{
If (root-> leftchild = NULL & root-> rigthchild = NULL) Count ++;
Trav_leaf (root-> leftchild );
Trav_leaf (root-> rigthchild );
}
Else
Return count;
}
Int posttreedepth (btree BT)
{
If (BT! = NULL)
{
H1 = posttreedepth (BT-> leftchild );
H2 = posttreedepth (BT-> rigthchild );
High = (h1> = h2 )? H1: H2;
Return (high + 1 );
}
Else return 0;
}
// Main Function
Int main ()
{
Btree Bt;
Cout <"OK! "<Endl;
Create (BT );
Cout <"DLR :";
Preorder_dlr (BT );
Cout <Endl;
/*
Cout <"LDR :";
Preorder_ldr (BT );
Cout <Endl;
Cout <"LRD :";
Preorder_lrd (BT );
Cout <Endl;
*/
Int getcout = trav_leaf (BT );
Cout <"Number of leaf nodes:" <getcout <Endl;
Cout <"tree depth:" <posttreedepth (BT) <Endl;
Cout <"high ="