文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

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

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

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

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


Heavenkiller(原创)


N叉树的每一节点度数都相同,为N
using System;
using System.Collections;
namespace DataStructure


{


     ///


     /// NaryTree 的摘要说明。-----N叉树


     ///


     public class NaryTree:Tree


     {


         // member variables


         protected object key;


         protected uint degree;


         protected ArrayList treeList=new ArrayList();


         //protected uint height=0;//暂时默认为0


 


         //create an empty tree whose attribute of degree is _degree


         public NaryTree(uint _degree)


         {


              //


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


              //


              this.key=null;


              this.degree=_degree;


              this.treeList=null;


         }


         //构造一棵叶子结点的N叉树


         public NaryTree(uint _degree,object _key)


         {


              this.key=_key;


              this.degree=_degree;


              this.treeList=new ArrayList();


              this.treeList.Capacity=(int)_degree;


 


              for(int i=0;i

              {


                  


                   this.treeList.Add( this.GetEmptyInstance(_degree) );


              }


         }


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


         protected virtual object GetEmptyInstance(uint _degree)


         {    return new NaryTree(_degree); }


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


         //judge whether the tree is an empty tree


         public override bool IsEmpty()


         {    return this.key==null; }


         //判定是否是叶子结点。如果即不是空树且每一棵子树均为空树,则为叶子结点


         public override bool IsLeaf()


         {


              if(IsEmpty())


                   return false;


              for(uint i=0;i

              {


                   if(  !(this[i].IsEmpty()) )


                       return false;


              }


              return true;


         }


         //-----------------------------------Inherited Attributes---------------------------------


         public override object Key


         {


              get


              {


                   return this.key;


              }


         }


         //索引器


         public override Tree this[uint _index]


         {


              get


              {


                  


                   if( _index>=this.degree )


                       throw new Exception("My:out of index!");//如果出界,则抛出异常


                   if( this.IsEmpty() )


                       return null;//如果是空树,则索引器返回一个 null


                   return (Tree)this.treeList[(int)_index];


              }


              set


              {


                   this.treeList[(int)_index]=value;


              }


         }


相关阅读 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——一款好用的电子日记本