明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

數(shù)據(jù)結(jié)構(gòu)與算法(C#完成)---AVLTree(二)

[摘要]//---------------override-------------------- public override void AttachKey(object _obj) if(!IsEmpty()) throw new Exception("My:th...

 //---------------override--------------------
 public override void AttachKey(object _obj)
 {
     if(!IsEmpty())
         throw new Exception("My:this node must be a empty tree node!");
     this.key=_obj;
     //產(chǎn)生一個(gè)degree長的數(shù)組,并將其初始化為空樹
     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;
 } //在改動(dòng)樹的結(jié)構(gòu)后平衡樹
 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;}
 }