#include <iostream>
using namespace std;
//BST的节点
typedef struct node
{
int key;
struct node *lChild , *rChild ;
}Node, *BST;
//在给定的BST中插入节点,数据域为element,使之成为新的BST
bool BSTInsert (Node * &p, int element)
{
if (Null == p)//空树
{
p = new Node ;
p ->key = element;
p ->lChild = p ->rChild = Null;
return true;
}
if(element == p ->key)//BST中不能有相等的值
return false;
if(element < p->key)
return BSTInsert(p ->lChild, element);//递归
return BSTInsert(p-> rChild, element);//递归
}
二叉排序树的建立过程
最新推荐文章于 2023-05-28 14:39:05 发布