首页 > 计算机考试 > 软件水平考试 > 软件指导 > 数据结构与算法(C#实现)系列---AVLTree(二)
数据结构与算法(C#实现)系列---AVLTree(二)

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

评论:0 | 责任编辑:Michael

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

}

//---------------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();
}
编辑整理:考试啦网站

本  文:数据结构与算法(C#实现)系列---AVLTree(二)
用户名: 密码: 匿名 [免费注册会员]
最新评论
编辑推荐文章
一周阅读排行