特点
1. data域不允许重复
2. 左节点的data值小于父亲节点的data 右边节点的data大于父亲节点的data
3. 结构上多了一个指向父亲节点的指针 可以回退 方便查询
4. 每一颗子树也是一个二叉搜索树
5. 其中序遍历结果:数字从小到大
构建
// 结点
每个结点只有一个有效父亲结点
function TreeNode(x) {
this.val = x;
this.left = null;
this.right = null;
this.lParent = null;
this.rParent = null;
this.appendLeft = function(node){
this.left = node;
}
this.appendRight = function(node) {
this.right = node;
}
this.appendLeftParent = function(node){
this.lParent = node;
}
this.appendRightParent = function(node){
this.rParent = node;
}
}
// 查找树构建
function BSTree(){
this.root = null;
this.insert = function(node){
if(!this.root){
this.root = node;
}
else{
// 从根节点开始比较
let cur = this.r