#include <iostream>
using namespace std;
/*
*二分搜索树BST
*/
typedef struct btree {
int data;
struct btree* lchild;
struct btree* rchild;
btree() {
lchild = rchild = NULL;
data = 0;
}
}btnode;
void insertBST(btnode*& root, int num) {
if (root == NULL) {
root = new btnode;
root->data = num;
}
else {
//根据二分搜索树性质 进行递归
if (root->data > num) {
insertBST(root->lchild, num);
}
else if (root->data < num) {
insertBST(root->rchild, num);
}
else {
cout << "重复插入" << endl;
}
}
}
bool isExist(btnode* root, int num) {
if (root == NULL) {
return false;
}
if (root->data == num) {
return true;
}
else if (root->data > num) {
return isExist(root->lchild, num);
}
else {
return isExist(root->rchild, num);
}
}