Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > C#.NET > 数据结构与算法(C#实现)系列---AVLTree(一)
【标  题】:数据结构与算法(C#实现)系列---AVLTree(一)
【关键字】:C,C#,结构,数据结构,AVLTree
【来  源】:网络

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

Your Ad Here

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

using System;

using System.Collections;

 

namespace DataStructure

{

     /// <summary>

     /// AVLTree 的摘要说明。-----平衡二叉查找树

     /// </summary>

     public class AVLTree:BST

     {

         protected int height;//空树的高定义为-1;

         //构造一棵空的二叉查找树

         public AVLTree():base()

         {

              //

              // TODO: 在此处添加构造函数逻辑

              //

              height=-1;

         }

         public AVLTree(object _obj):base(_obj)

         {

              height=0;

         }

         //------------------------------------------------------------------

         protected override object GetEmptyInstance(uint _degree)

         {    return new AVLTree(); }

         //------------------------------------------------------------------

 

         protected int BalanceFactor()

         {

              if (this.IsEmpty() )

                   return 0;

              return ((AVLTree)this.Left).height-((AVLTree)this.Right).height;

         }

         //调整高度

         protected void AdjustHeight(){   this.height=Math.Max( ((AVLTree)this.Left).height, ((AVLTree)this.Right).height)+1;     }

         //平衡时的四种旋转方式

         protected void LLRotation()

         {

              if( this.IsEmpty() )

                   throw new Exception("My:invalid operation!");

              AVLTree avlB=new AVLTree(this.key);

                            avlB.AttachSubtree(1,(AVLTree)this[0][1]);

              avlB.AttachSubtree(2,(AVLTree)this[1]);

 

             

              this.key=this[0].Key;

              this[0]=this[0][0];

              this[1]=avlB;

              //调整两个节点的高度

              ((AVLTree)this.Right).AdjustHeight();

              this.AdjustHeight();

         }

         protected void LRRotation()

         {

              if( this.IsEmpty() )

                   throw new Exception("My:invalid operation!");

              ((AVLTree)this.Left).RRRotation();

              this.LLRotation();

 

         }

         protected void RRRotation()

         {

              if( this.IsEmpty() )

                   throw new Exception("My:invalid operation!");

              AVLTree avlB=new AVLTree(this.key);

             

 

              avlB.AttachSubtree(1,(AVLTree)this[0]);

              avlB.AttachSubtree(2,(AVLTree)this[1][0]);

 

              //avlA.AttachSubtree(1,avlB);

             

              //this=avlA;

              this.key=this[1].Key;

              this[0]=avlB;

              this[1]=this[1][1];

              //调整两个节点的高度

              ((AVLTree)this.Left).AdjustHeight();

              this.AdjustHeight();

         }

         protected void RLRotation()

         {

              if( this.IsEmpty() )

                   throw new Exception("My:invalid operation!");

              ((AVLTree)this.Right).LLRotation();

              this.RRRotation();

         }

数据结构与算法(C#实现)系列---AVLTree(二):【上一篇】
数据结构与算法(C#实现)系列---二叉树:【下一篇】
【相关文章】
  • 数据结构与算法(C#实现)系列---AVLTree(二)
  • C# 2.0新特性探究之模拟泛型和内置算法
  • 对C#泛型中的new()约束的一点思考
  • C#冒泡算法
  • 掌握C++ builder的除错艺术(2).1
  • C++ builder快捷键大全
  • 掌握C++ builder的除错艺术(2).2
  • Access Violations(访问冲突)
  • 使用 C++ Builder 创建应用程序
  • TCanvas
  • 【随机文章】
  • Netdump服务器建设
  • VS.NET setup project
  • Jasper库的在网络机器人监控中的应用
  • iptables下udp穿越结尾篇----iptables与socks5
  • Apache的基本设置
  • Unify eWave ServletExec泄露jsp源代码漏洞
  • 你真的了解.NET中的String吗?
  • 关于博维数据
  • cisco 限制BT的几种方法
  • STL的迭代器--Iterator
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.