设为首页
加入收藏
站内地图
旧版入口
当前位置:首页 > 站长学院 > 网络编程 > C#

数据结构与算法(C#实现)---AVLTree(二)

作者:佚名 出处:网络转载 时间:10-07 点击:

内容载入中...

 //---------------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;}
 }
收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口

站长学院

推荐信息