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

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

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

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

来源: 发布时间:星期五, 2009年1月9日 浏览:20次 评论:0
publicoverrideuDegree
    {
       get
       {
         this.degree;
       }
    }
           
    //只用于空树结点
    publicvirtualvoidAttachKey(object_obj)
    {
       (!IsEmpty)
         throwException("My:thisnodemustbeaemptytreenode!");
       this.key=_obj;
       this.treeList=ArrayList;//产生个degree长,并将其化为空树
       this.treeList.Capacity=()this.degree;
       for(i=0;i<this.degree;i)
       {
         treeList.Add(NaryTree(this.degree));
       }
       /*
       foreach(objecttmpObjhis.treeList)
       {
         tmpObj=NaryTree(this.degree);
       }
       */
    }
    //只用于叶子结点将叶子结点变为个空结点并返回叶子结点关键字引用
    publicvirtualobjectDetachKey
    {
       (!IsLeaf)
         throwException("My:thisnodemustbealeafnode!");
       objectresult=this.key;//storethisleafnodetemporary
       this.key=null;
       this.treeList=null;
       result;
    }
    //将子树连接到指定树第num个结点上前提是这个结点必须是空结点,并且度数相同否则抛出异常
    publicvirtualvoidAttachSubtree(unum,NaryTree_naryTree)
    {
       (this.IsEmpty)
         throwException("My:itcan'tbeaemptytree!");
       (!(this[num-1].IsEmpty)|this.degree!=_naryTree.degree)
         throwException("My:this[i-1]mustbeemptyandtheyshouldhavethesamedegree!");
       this[num-1]=_naryTree;
    }
    //仅为非空树定义从给定树中删去它第i棵子树并连上个空树,度数相同并且返回删除子树引用
    publicvirtualNaryTreeDetachSubtree(unum)
    {
       (IsEmpty)
         throwException("My:itcan'tbeempty!");
       NaryTreetmpTree=this;
       ((NaryTree)this[num-1]).key=null;
       ((NaryTree)this[num-1]).treeList=null;
       this;
    }
  }
}


0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: