掌握二叉排序树的查找、插入、删除、建立算法的思想及程序实现。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef struct Node{
Node *ls,*rs;
int val;
}Node;
typedef struct BSTree{
Node *root;
BSTree(){root=NULL;}
public:
Node* newnode(){
Node *p=(Node*)malloc(sizeof(Node));
p->ls=p->rs=NULL;
return p;
}
string Search(int x,Node *a){
if(a->val==x){
return " ";
}
if(a->val>x) return "0"+Search(x,a->ls);
return "1"+Search(x,a->rs);
}
Node* Insert(int x,Node *a){
if(a==NULL){
a=newnode();
a->val=x;
}else if(a->val>x){
a->ls=Insert(x,a->ls);
}else{
a->rs=Insert(x,a->rs);
}
return a;
}
Node* Delete_Search(int x,Node *a){