平衡二叉树(c++)

定义

平衡树(Balance Tree,BT)
指的是,任意节点的子树的高度差都小于等于1。常见的符合平衡树的有,B树(多路平衡搜索树)、AVL树(二叉平衡搜索树)等。平衡树可以完成集合的一系列操作,
时间复杂度和空间复杂度相对于“2-3树”要低,在完成集合的一系列操作中始终保持平衡,为大型数据库的组织、索引提供了一条新的途径

平衡二叉树类

继承二叉树类
二叉树类代码(GitHub):https://github.com/rebelsisyphus/vscode/blob/main/.vscode/data%20structure/Bintree/tree.h
二叉树类(csdn):https://blog.csdn.net/qq_40602655/article/details/114552635
功能:旋转调整树高,插入删除操作

template <class T>
class AvlTree:public BinTree<T>{
   
    protected:
       BinTreeNode<T> * Insertnode(BinTreeNode<T> *subtree,T &x);
       BinTreeNode<T> * Deletenode(BinTreeNode<T> *subtree,T &x);
       BinTreeNode<T> * SingleLeftRotation(BinTreeNode<T> *subtree);
       BinTreeNode<T> * SingleRightRotation(BinTreeNode<T> *subtree);
       BinTreeNode<T> * LeftRightRotation(BinTreeNode<T> *subtree);
       BinTreeNode<T> * RightLeftRotation(BinTreeNode<T> *subtree);
       BinTreeNode<T> *  Maxnode(BinTreeNode<T> *subtree){
   
            BinTreeNode<T> *temp=subtree;
            while(temp->rightChild!=NULL){
   
                temp=temp->rightChild;
            }
            return temp;
       }
       BinTreeNode<T> *  Minnode(BinTreeNode<T> *subtree){
   
           BinTreeNode<T> *temp=subtree;
            while(temp->leftChild!=NULL){
   
                temp=temp->leftChild;
            }
            return temp;
       }
    public:
       /*BinSearchTree(){this->root=NULL;};
       BinSearchTree(T x){
           this->root=new BinTreeNode<T>(x);
       }
       ~BinSearchTree(){this->deleteall(this->root);}*/
       void buildavltree();
       void Insertnode(T &x){
    this->root=Insertnode(this->root,x);}
       void Deletenode
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值