首页 | 旅游 | 健康 | 时尚 | 下载 | 论坛 | 图文 | 专题 | 地图
资讯 IT人 电脑入门 操作系统 上网 办公 技巧 硬件 软件 网络 图像 多媒体 程序 数据库 网页制作 网站开发 网游 安全 加密 企业

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

巧巧读书 2006-05-05   技术论坛

          数据结构与算法(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;}}

        

}

本类最热图文
巧巧读书图文推荐
Google
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章