数据结构与算法(C#实现)系列---AVLTree(二)(外摘)
2007-07-04 17:48
871 查看
数据结构与算法(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;}}
}
//---------------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;}}
}
相关文章推荐
- 数据结构与算法(C#实现)系列---演示篇(一)(外摘)
- 数据结构与算法(C#实现)系列---二叉树
- 数据结构与算法(C#实现)系列---二叉树
- 【数据结构与算法】c# Dictionary内部实现
- 数据结构——平衡二叉搜索树(AvlTree)的实现
- 转:C#数据结构和算法学习系列十三----链表
- 数据结构与算法(C#实现)系列---AVLTree(二)
- 转:C#数据结构和算法学习系列九----String类和StringBuilder类
- 转:C#数据结构和算法学习系列十四----集合
- 数据结构与算法---C#实现LinkedList实例
- 常用数据结构及算法C#/Java实现
- 数据结构与算法(C#实现)系列---AVLTree(二)
- 转:C#数据结构和算法学习系列十----正则表达式
- 数据结构算法之排序系列Java、C源码实现(3)--直接选择排序
- 转:C#数据结构和算法学习系列十一----构建字典DictionaryBase 类和SortedList 类
- 【数据结构与算法基础】AVL树 / AVL Tree
- 转:C#数据结构和算法学习系列十二----散列HashTable类
- C#List随机交换取数据(C#实现的洗牌算法)
- 【数据结构与算法】【排序】直接插入排序的代码实现
- c# 数据结构算法学习一:冒泡排序