#include<iostream>
using namespace std;
class BiNode{
private:
BiNode *LChild, *RChild;
int Data;
public:
BiNode(): LChild(NULL),RChild(NULL),Data(-1){}
BiNode(BiNode* l,BiNode* r,int d): LChild(l),RChild(r),Data(d){}
BiNode(int d): LChild(NULL),RChild(NULL),Data(d) {}
BiNode* Get_L() {return LChild;}
BiNode* Get_R() {return RChild;}
int Get_D() {return Data;}
void Change (BiNode* l, BiNode* r,int d){LChild = l,RChild = r, Data = d;}
void Change_L(BiNode* l) {LChild = l;}
void Change_R(BiNode* r) {RChild = r;}
void Change_D(int d) {Data = d;}
};
BiNode* CreateTree(BiNode* T)
{
int D = -1;
cout << " please cin the number " << endl;
cin >> D;
if(-1 == D)
{T = NULL; return T;}
else
{
if( !(T = new BiNode(D)))
return T;
else
{
T->Change_L(CreateTree(T->Get_L() ) );
T->Change_R(CreateTree(T->Get_R() ) );
return T;
}
}
}
void DeleteTree(BiNode* T)
{
if(NULL == T)
{return;}
else
{
if(T->Get_L() != NULL)
DeleteTree(T->Get_L() );
if(T->Get_R() != NULL)
DeleteTree(T->Get_R());
cout << T->Get_D() << endl;
delete T;
return;
}
}
void PreTraverse(BiNode *T)
{
if(NULL == T)
return;
else
{
cout << T->Get_D() << endl;
PreTraverse(T->Get_L());
PreTraverse(T->Get_R());
return;
}
}
int main()
{
BiNode* BT = NULL;
cout << "begin Create the tree " << endl;
BT = CreateTree(BT);
PreTraverse(BT);
cout << " begin delete the tree " << endl;
DeleteTree(BT);
return 0;
}
using namespace std;
class BiNode{
private:
BiNode *LChild, *RChild;
int Data;
public:
BiNode(): LChild(NULL),RChild(NULL),Data(-1){}
BiNode(BiNode* l,BiNode* r,int d): LChild(l),RChild(r),Data(d){}
BiNode(int d): LChild(NULL),RChild(NULL),Data(d) {}
BiNode* Get_L() {return LChild;}
BiNode* Get_R() {return RChild;}
int Get_D() {return Data;}
void Change (BiNode* l, BiNode* r,int d){LChild = l,RChild = r, Data = d;}
void Change_L(BiNode* l) {LChild = l;}
void Change_R(BiNode* r) {RChild = r;}
void Change_D(int d) {Data = d;}
};
BiNode* CreateTree(BiNode* T)
{
int D = -1;
cout << " please cin the number " << endl;
cin >> D;
if(-1 == D)
{T = NULL; return T;}
else
{
if( !(T = new BiNode(D)))
return T;
else
{
T->Change_L(CreateTree(T->Get_L() ) );
T->Change_R(CreateTree(T->Get_R() ) );
return T;
}
}
}
void DeleteTree(BiNode* T)
{
if(NULL == T)
{return;}
else
{
if(T->Get_L() != NULL)
DeleteTree(T->Get_L() );
if(T->Get_R() != NULL)
DeleteTree(T->Get_R());
cout << T->Get_D() << endl;
delete T;
return;
}
}
void PreTraverse(BiNode *T)
{
if(NULL == T)
return;
else
{
cout << T->Get_D() << endl;
PreTraverse(T->Get_L());
PreTraverse(T->Get_R());
return;
}
}
int main()
{
BiNode* BT = NULL;
cout << "begin Create the tree " << endl;
BT = CreateTree(BT);
PreTraverse(BT);
cout << " begin delete the tree " << endl;
DeleteTree(BT);
return 0;
}