盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

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

时间:2024/11/14作者:未知来源:盾怪网教程人气:

[摘要]//---------------override-------------------- public override void AttachKey(object _obj) if(!...

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

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




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版