当前位置:系统之家 > 技术开发教程 > 详细页面

数据结构与算法(C#完成)---AVLTree(二)

数据结构与算法(C#完成)---AVLTree(二)

更新时间:2022-09-14 文章作者:未知 信息来源:网络 阅读次数:


 //---------------override--------------------
 public override void AttachKey(object _obj)
 {
     if(!IsEmpty())
         throw new Exception("My:this node must be a empty tree node!");
     this.key=_obj;
     //产生一个degree长的数组,并将其初始化为空树
     this.treeList=new ArrayList();
     this.treeList.Capacity=(int)this.degree;
     for(int i=0;i<this.degree;i++)
     {
         treeList.Add(new AVLTree());
     }
     //
     this.height=0;
 } //在改动树的结构后平衡树
 public override void Balance()
 {
     this.AdjustHeight();
     //大于1则说明不平衡
     if( Math.Abs(this.BalanceFactor())>1)
     {
         if(this.BalanceFactor()>0)
         {
             if (((AVLTree)this.Left).BalanceFactor()>0)
                 this.LLRotation();
             else
                 this.LRRotation();
         }
         else
         {
              if (((AVLTree)this.Right).BalanceFactor()<0)
                  this.RRRotation();
              else
                  this.RLRotation();
         }
     }
 } public int Height
 {
     get{return this.height;}
 }

温馨提示:喜欢本站的话,请收藏一下本站!

本类教程下载

系统下载排行