①定义
二叉搜索树:对于一棵二叉树,每个节点的值大于该节点左子树的所有节点的值,小于该节点右子树的所有节点的值。
②二叉搜索树的创建
typedef struct Node *node;
struct Node{
node left;
node right;
int data;
};
node Insert(node root,int x){ //二叉搜索树的节点插入
if(!root){
node tmp = (node)malloc(sizeof(struct Node));
tmp->left = NULL;
tmp->right = NULL;
root = tmp;
}
else{
if(x > root->data){
root->right = Insert(root->right, x);
}else if(x < root->data){
root->left = Insert(root->left, x);
}
}
return root;
}