- 数据结构与算法(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;}}
-
-
}
努力加载评论中...
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步