您的位置:首页精文荟萃软件资讯 → 数据结构与算法C#实现系列---N叉树二

数据结构与算法C#实现系列---N叉树二

时间:2004/10/8 13:17:00来源:本站整理作者:蓝点我要评论(0)

数据结构与算法(C#实现)系列---N叉树(二)


Heavenkiller(原创)


public override uint Degree


         {


              get


              {


                   return this.degree;


              }


         }
                     


         //只用于空树结点


         public virtual void AttachKey(object _obj)


         {


              if(!IsEmpty())


                   throw new Exception("My:this node must be a empty tree node!");


              this.key=_obj;


              this.treeList=new ArrayList();//产生一个degree长的数组,并将其初始化为空树


              this.treeList.Capacity=(int)this.degree;


 


              for(int i=0;i

              {


                   treeList.Add(new NaryTree(this.degree));


              }


              /*


              foreach(object tmpObj in this.treeList)


              {


                   tmpObj=new NaryTree(this.degree);


              }


              */


         }


         //只用于叶子结点,将叶子结点变为一个空结点,并返回叶子结点关键字的引用


         public virtual object DetachKey()


         {


              if(!IsLeaf())


                   throw new Exception("My:this node must be a leaf node!");


              object result=this.key;//store this leaf node temporary


              this.key=null;


              this.treeList=null;


 


              return result;


         }


         //将子树连接到指定树的第num个结点上,前提是这个结点必须是空结点,并且度数相同,否则抛出异常


         public virtual void AttachSubtree(uint num,NaryTree _naryTree)


         {


              if(this.IsEmpty())


                   throw new Exception("My:it can't be a empty tree!");


              if(!(this[num-1].IsEmpty()) | this.degree!=_naryTree.degree )


                   throw new Exception("My:this[i-1] must be empty and they should have the same degree!");


              this[num-1]=_naryTree;


         }


         //仅为非空树定义,从给定树中删去它的第i棵子树并连上一个空树,度数相同,并且返回删除的子树引用


         public virtual NaryTree DetachSubtree(uint num)


         {


              if (IsEmpty())


                   throw new Exception("My:it can't be empty! ");


              NaryTree tmpTree=this;


              ((NaryTree)this[num-1]).key=null;


              ((NaryTree)this[num-1]).treeList=null;


 


              return this;


         }


     }


}


 


相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 360快剪辑怎么使用 36金山词霸如何屏幕取词百度收购PPS已敲定!3

最新文章 微信3.6.0测试版更新了微信支付漏洞会造成哪 360快剪辑怎么使用 360快剪辑软件使用方法介酷骑单车是什么 酷骑单车有什么用Apple pay与支付宝有什么区别 Apple pay与贝贝特卖是正品吗 贝贝特卖网可靠吗

人气排行 xp系统停止服务怎么办?xp系统升级win7系统方电脑闹钟怎么设置 win7电脑闹钟怎么设置office2013安装教程图解:手把手教你安装与qq影音闪退怎么办 QQ影音闪退解决方法VeryCD镜像网站逐个数,电驴资料库全集同步推是什么?同步推使用方法介绍QQ2012什么时候出 最新版下载EDiary——一款好用的电子日记本