ITPub博客

首页 > 应用开发 > IT综合 > 数据结构与算法(C#实现)系列---AVLTree(二)(转)

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

原创 IT综合 作者:BugRobber 时间:2007-07-06 15:46:39 0 删除 编辑
数据结构与算法(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;}}

}

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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8781179/viewspace-924560/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    372
  • 访问量
    200911