Dy # incrude
Using namespace std;
Struct node {// Node
Int data;
Node * LCHILD;
Node * rCHILD;
}
Node * cretenode (int data) //
{
Node * node = new node;
Node-> Data = DATA;
Node-> LCHILD = 0;
Node-> rchild = 0;
Return node;
}
Node * buildtree () // build tree
{
Node * root = 0;
Return root;
}
Void inserttree (node * & root, int data) // inserted an orderly tree
{
Node * node = createnode (data);
IF (! root) root = node;
Else IF (Node-> Data
Else InsertTree (root-> rchild, node-> data);
Return;
}
Void PrintTree (Node * root) // Assembly print
{
IF (! root) return;
PRINTTREE (root-> lchild);
COUT << root-> data << "
PRINTTREE (root-> rchild);
}
INT Finder (Node * root, int data)
{
IF (! root) Return 0;
IF (root-> data == data) Return 1;
Else Return (Finder (Root-> Lchild, Data) || Finder (root-> rchild, data);
}
Void Findfather (Node * root, Int i, int J)
{
IF (! root) return;
IF (Finder (root, i) &&finder (root, j))
{
IF (Finder (root-> lchild, i) &&finder (root-> lchild, j)) Findfather (root-> lchild, i, j);
Else IF (Finder (root-> rchild, i) &&finder (root-> rchild, j)) Findfather (root-> rchild, i, j);
Else Cout << "They are:" << root-> data << Endl;
}
Else Cout << "There is no node is not in the tree" << Endl;
}
Int main (int Argc, char * argv [])
{
Int Data, I, J;
Node * root = buildtree ();
Cout << "Please enter your data with -1 end" << endl;
CIN >> DATA;
While (Data! = - 1)
{
INSERTTREE (root, data);
CIN >> DATA;
}
PRINTTREE (root);
Cout << Endl;
Cout << "Please enter the two data you want to find" << Endl;
CIN >> I >> J;
Findfather (root, i, j); system ("pause");
Return 0;
}
Maybe a little problem