void Insert(BT **bt,ElemType x){
if(*bt==NULL){BT *np=(BT*)malloc(sizeof(BT));
np->data=x;np->left=np->right=NULL;
*bt=np;
}else{
if(x<(*bt)->data) Insert(&(*bt)->left,x);
else Insert(&(*bt)->right,x);
}
}
void CreateBSTree(BT **bt,ElemType a[],int n){
int i;
*bt=NULL;
for(i=0;i<n;i++)
Insert(bt,a[i]);
}
ElemType *Find(BT *bt,ElemType x){
if(bt==NULL) return NULL;
if(bt->data==x) return &(bt->data);
else if(x<bt->data) return Find(bt->left,x);
else if(x>bt->data) return Find(bt->right,x);
}
int Delete(BT **bt,ElemType x){
BT *tmp;
tmp=*bt;
if(*bt==NULL) return 0;
if(x<(*bt)->data) return Delete(&(*bt)->left,x);
if(x>(*bt)->data) return Delete(&(*bt)->right,x);
if((*bt)->left==NULL){
*bt=(*bt)->right;
free(tmp);return 1;
}else if((*bt)->right==NULL){
*bt=(*bt)->left;
free(tmp);return 1;
}else{
if((*bt)->left->right==NULL){
(*bt)->data=(*bt)->left->data;
return Delete(&((*bt)->left),(*bt)->left->data);
}else{
BT *p1=*bt,*p2=p1->left;
while(p2->right!=NULL) {p1=p2;p2=p2->right;}
(*bt)->data=p2->data;
return Delete(&(p1->right),p2->data);
}
}
}