专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »DotNet » 数据结构与算法分析:数据结构和算法_C#实现N叉树(1) »正文

数据结构与算法分析:数据结构和算法_C#实现N叉树(1)

来源: 发布时间:星期五, 2009年1月9日 浏览:17次 评论:0
  N叉树节点度数都相同为N

using;
using.Collections;
DataStructure
{
  ///<summary>
  ///NaryTree摘要介绍说明-----N叉树
  ///</summary>
  publicNaryTree:Tree
  {
    //membervariables
    protectedobjectkey;
    protectedudegree;
    protectedArrayListtreeList=ArrayList;
    //protecteduheight=0;//暂时默认为0
    //createanemptytreewhoseattributeofdegreeis_degree
    publicNaryTree(u_degree)
    {
       //
       //TODO:在此处添加构造逻辑
       //
       this.key=null;
       this.degree=_degree;
       this.treeList=null;
    }
    //构造棵叶子结点N叉树
    publicNaryTree(u_degree,object_key)
    {
       this.key=_key;
       this.degree=_degree;
       this.treeList=ArrayList;
       this.treeList.Capacity=()_degree;
       for(i=0;i<this.treeList.Capacity;i)
       {
          
         this.treeList.Add(this.GetEmptyInstance(_degree));
       }
    }
    //-----------------------------------------------------------------
    protectedvirtualobjectGetEmptyInstance(u_degree)
    {  NaryTree(_degree);}
    //-------------------------------------------------------------------
    //judgewhetherthetreeisanemptytree
    publicoverrideboolIsEmpty
    {  this.keynull;}
    //判定是否是叶子结点如果即不是空树且每棵子树均为空树则为叶子结点
    publicoverrideboolIsLeaf
    {
       (IsEmpty)
         false;
       for(ui=0;i<this.degree;i)
       {
         ( !(this[i].IsEmpty))
           false;
       }
       true;
    }
    //-----------------------------------InheritedAttributes---------------------------------
    publicoverrideobjectKey
    {
       get
       {
         this.key;
       }
    }
    //索引器
    publicoverrideTreethis[u_index]
    {
       get
       {
          
         (_index>=this.degree)
           throwException("My:outofindex!");//如果出界则抛出异常
         (this.IsEmpty)
           null;//如果是空树则索引器返回个null
         (Tree)this.treeList[()_index];
       }
       
       {
         this.treeList[()_index]=value;
       }
    }


0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: