首 页 | 精品电影 | 音乐天堂 | 在线游戏 | Flash MTV | 三湘书屋 | 幽默笑话 | 三湘图库 | 美女写真 | IT知识库 | QQ贴图 | 加入书签

网页制作网络编程图形图象操作系统冲浪宝典软件教学网络安全认证考试通信技术电子商务业内动态书籍教程原码

最近更新 文章分类 多媒体类 精品软件

本站搜索:
您的位置:三湘时空 -> IT知识库 -> 文章分类 -> C#教程 -> 数据结构与算法(C#实现)系列---N叉树(一)  
数据结构与算法(C#实现)系列---N叉树(一)


文章类别:C#教程 来源: 作者: 发表日期:2005-10-4 字体:[ ]

小游戏 | 在线影院 | 幽默笑话 | 源码下载 | Flash MTV | 音乐试听 | 书屋 | 美女写真

数据结构与算法(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#实现)系列---广义树(二) 下一篇:VC# .Net中使用Crystal Report
本栏目热门文章
·C#语言初级入门(1) 2005-10-4
·C# 中的类型转换 2006-4-10
·C#语言初级入门(3) 2005-10-4
·C#语言初级入门(2) 2005-10-4
·C#,深入浅出全接触(一) 2005-10-4
·c#学习笔记(1) 2005-10-4
·C# 3.0语言详解之基本的语言增强 2005-10-22
·C#的前途如何? 2005-10-4
·C#,深入浅出全接触(二) 2005-10-4
·基于C#的接口基础教程之一 2005-10-4
新近更新文章
·C# 3.0新特性初步研究 Part1:使用隐含类型的本地变量 2006-6-12
·C# 4.0语言将出现重大改变,带来一段Code Preview 2006-6-12
·C# 3.0新特性初步研究 Part6:使用查询表达式 2006-6-12
·C# 3.0新特性初步研究 Part5:匿名类型 2006-6-12
·C# 3.0新特性初步研究 Part4:使用集合类型初始化器 2006-6-12
·C# 3.0新特性初步研究 Part3:使用拉姆达表达式 2006-6-12
·C# 3.0新特性初步研究 Part2:使用扩展方法 2006-6-12
·c#泛型学习(二) 2006-5-12
·c#2.0泛型学习(一) 2006-5-12
·C# 编码规范和编程好习惯 2006-4-30
首 页 | 软件发布 | 广告联系 | 下载帮助 | 意见反馈 | 网站地图
  CopyRight? 2002-2004 WWW.SXSKY.NET? All Rights Reserved
三湘时空 站长QQ:82675303 Email: