///
///
// binary tree data structure bintree.h //
///
//
#include
Template
Template
Class Treenode
{
protected:
Friend Class Bintree
Treenode (): lchild (null), rChild (null) {}
TYPE DATA;
Treenode * lchild; // left, right
Treenode * rchild;
}
Template
Class bintree
{
Friend void bintree_pre (bintree
Friend void bintree_ino (bintree
Friend void bintree_pos (bintree
Friend void bintree_destroy (bintree
PUBLIC:
Bintree (): root (null) {}
Void creatree (); // Creating a binary tree, the main process
Void Creattree (Treenode
Void Pretree (Treenode
Void inotree (TREENODE
Void PostRee (Treenode
Void Destroy (TREENODE
Bool isempty ();
protected:
TREENODE
}
Template
Void bintree
{
CreatTree (root, 1);
}
Template
Void Bintree
{
TREENODE
Point = New Treenode
Cout << "Enter the node data item:";
CIN >> POINT-> DATA;
Switch (k)
{
Case 1: root = POINT; BREAK;
Case 2: child-> lchild = points;
Case 3: Child-> rchild = Point; Break;
}
CHAR TEMP;
Cout << "The" << Point-> Data << "node has a left subtree Y / any key:";
CIN >> TEMP;
IF (Temp == 'Y' || TEMP == 'Y')
{
CreatTree (Point, 2);
}
Cout << "The << Point-> Data <<" node has a right sub-tree Y / any key: "; cin >> Temp;
IF (Temp == 'Y' || TEMP == 'Y')
{
CreatTree (Point, 3);
}
}
Template
Void bintree
{
IF (Point! = null)
{
Cout << "<< Point-> Data;
PRETREE (Point-> LCHILD);
PRETREE (Point-> rchild);
}
}
Template
Void Bintree
{
IF (Point! = null)
{
Inotree (Point-> Lchild);
Cout << "<< Point-> Data;
INOTREE (Point-> rchild);
}
}
Template
Void bintree
{
IF (Point! = null)
{
Postree (Point-> LCHILD);
Postree (Point-> rchild);
Cout << "<< Point-> Data;
}
}
Template
Bool bintree
{
Return root == NULL;
}
Template
Void Bintree
{
IF (Point! = null)
{
Destroy (Point-> LCHILD);
DESTROY (POINT-> rchild);
Delete point;
}
}