数据结构与算法 (C# 实现 ) 系列 ---AVLTree (二) //---------------override-------------------- public override void AttachKey( object _obj) {" name="description" />

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

发表于:2007-06-21来源:作者:点击数: 标签:
MI LY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> 数据结构与算法 (C# 实现 ) 系列 ---AVLTree (二) //---------------override-------------------- public override void AttachKey( object _obj) {

   

MILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">          数据结构与算法(C#实现)系列---AVLTree(二)

         //---------------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;}}

        

}

原文转自:http://www.ltesting.net

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)