代码:
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef struct Node
{
int element;
struct Node * left;
struct Node * right;
}TreeNode,*BSTree,*ptrnode;
ptrnode Insert(int x,BSTree &T)
{
if(NULL==T)
{
T=(ptrnode)malloc(sizeof(TreeNode));
if(T==NULL)
{
cout<<"out of space!"<<endl;
exit(0);
}
T->element=x;
T->left=T->right=NULL;
}
else if(x<T->element)
{
T->left=Insert(x,T->left);
}
else if(x>T->element)
{
T->right=Insert(x,T->right);
}
return T;
}
ptrnode Find(int x,BSTree &T)
{
if(NULL==T)
return NULL;
if(x<T->element)
return Find(x,T->left);
else if(x>T->element)
return Find(x,T->right);
else
return T;
}
void MakeEmpty(BSTree &T)//destroy the BSTree
{
if(NULL==T)
return ;
else
{
if(T->left!=NULL)
MakeEmpty(T->left)