数据结构和C#算法实现---AVLTree(我)

数据结构和C#算法实现---AVLTree(我)
使用系统;
使用系统集合;

空间数据结构
{
X
/ / 的实现/注。----平衡二叉查找树
X
公共类的实现:BST
{
受保护的int高度;空树的高定义- 1;

结构二个二进制搜索树空
AVLTree():公共基础()
{

在这里添加构造函数逻辑

身高= 1;
}

公共avltree(对象_obj):基地(_obj)
{
高度= 0;
}

/ / ------------------------------------------------------
保护覆盖对象getemptyinstance(个_degree)
{
返回新的实现();
}
/ / ------------------------------------------------------

int BalanceFactor(保护)
{
如果(this.isempty())
返回0;
返回(((AVLTree),左),高度((AVLTree),右)。高度;
}

高度调整
protected void()AdjustHeight
{
这个高度= math.max ((((( avltree),左),Height((AVLTree)这对高度)+ 1);
}

四平衡旋转
llrotation protected void()
{
如果(this.isempty())
抛出新异常():无效操作!;
实现管理局=新实现(这个关键);
AvlB.AttachSubtree(1,((AVLTree)这{ 0 } { 1 });
AvlB.AttachSubtree(2,((AVLTree)这{ 1 });

此键=此{ 0 }键;
此{ 0 } =此{ 0 } { 0 };
这{ 1 } =装甲架桥车;
/两节点高度调整
((AVLTree),AdjustHeight(右)。);
This.AdjustHeight();
}

lrrotation protected void()
{
如果(this.isempty())
抛出新异常():无效操作!;
((AVLTree),RRRotation(左));
this.llrotation();
}

rrrotation protected void()
{
如果(this.isempty())
抛出新异常():无效操作!;
实现管理局=新实现(这个关键);

AvlB.AttachSubtree(1,((AVLTree)这{ 0 });
AvlB.AttachSubtree(2,((AVLTree)这{ 1 } { 0 });

/ / avla.attachsubtree(1,管理局);

/ /本该;
此键=此{ 1 }键;
这{ 0 } =装甲架桥车;
此{ 1 } =此{ 1 } { 1 };
/两节点高度调整
((AVLTree),AdjustHeight(左));
This.AdjustHeight();
}

rlrotation protected void()
{
如果(this.isempty())
抛出新异常():无效操作!;
((AVLTree),LLRotation(右)。);
this.rrrotation();
}

tag:算法实现数据结构电脑软件AVLTree

相关内容