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