网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C#教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.SUNWEN教程之----C#进阶(六).
.数据结构与算法(C#实现)系列---树.
.基于C#的接口基础教程之七.
.C#中结构与类的区别.
.C# 编码规范和编程好习惯.
.基于C#的接口基础教程之三.
.C#和VB.net语法对比图.
.C#中的“装箱”(boxing)与“拆.
.基于C#的接口基础教程之六.
.基于C#的接口基础教程之五.
.C# 3.0新特性初步研究 Part4:使用.
.数据结构与算法(C#实现)系列----.
.C#基础—关于类 .
.漫谈C#编程中的多态与new关键字.
.C#中的数组和C++中数组的区别.
.datagridcolumnstyle重写,实现插.
.C# 3.0新特性体验之Lambda表达式.
.SUNWEN教程之----C#进阶(十).
.C# 4.0语言将出现重大改变,带来.
.C# 3.0新特性初步研究 Part6:使用.

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

发表日期:2004-2-7


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

Heavenkiller(原创)

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

{

     /// <summary>

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

     /// </summary>

     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.Capacity;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<this.degree;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;

              }

         }

上一篇:数据结构与算法(C#实现)系列---广义树(二) 人气:16043
下一篇:数据结构与算法(C#实现)系列---N叉树(二) 人气:20730
浏览全部数据结构与算法(C#实现)的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐