国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

數(shù)據(jù)結構與算法(C#實現(xiàn))系列---N叉樹(二)

2019-11-18 19:43:12
字體:
供稿:網(wǎng)友

數(shù)據(jù)結構與算法(C#實現(xiàn))系列---N叉樹(二)

Heavenkiller(原創(chuàng))

public override uint Degree

         {

              get

              {

                   return this.degree;

              }

         }
                     

         //只用于空樹結點

         public virtual void AttachKey(object _obj)

         {

              if(!IsEmpty())

                   throw new Exception("My:this node must be a empty tree node!");

              this.key=_obj;

              this.treeList=new ArrayList();//產(chǎn)生一個degree長的數(shù)組,并將其初始化為空樹

              this.treeList.Capacity=(int)this.degree;

 

              for(int i=0;i<this.degree;i++)

              {

                   treeList.Add(new NaryTree(this.degree));

              }

              /*

              foreach(object tmpObj in this.treeList)

              {

                   tmpObj=new NaryTree(this.degree);

              }

              */

         }

         //只用于葉子結點,將葉子結點變?yōu)橐粋€空結點,并返回葉子結點關鍵字的引用

         public virtual object DetachKey()

         {

              if(!IsLeaf())

                   throw new Exception("My:this node must be a leaf node!");

              object result=this.key;//store this leaf node temporary

              this.key=null;

              this.treeList=null;

 

              return result;

         }

         //將子樹連接到指定樹的第num個結點上,前提是這個結點必須是空結點,并且度數(shù)相同,否則拋出異常

         public virtual void AttachSubtree(uint num,NaryTree _naryTree)

         {

              if(this.IsEmpty())

                   throw new Exception("My:it can't be a empty tree!");

              if(!(this[num-1].IsEmpty()) | this.degree!=_naryTree.degree )

                   throw new Exception("My:this[i-1] must be empty and they should have the same degree!");

              this[num-1]=_naryTree;

         }

         //僅為非空樹定義,從給定樹中刪去它的第i棵子樹并連上一個空樹,度數(shù)相同,并且返回刪除的子樹引用

         public virtual NaryTree DetachSubtree(uint num)

         {

              if (IsEmpty())

                   throw new Exception("My:it can't be empty! ");

              NaryTree tmpTree=this;

              ((NaryTree)this[num-1]).key=null;

              ((NaryTree)this[num-1]).treeList=null;

 

              return this;

         }

     }

}

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 哈密市| 田东县| 柳林县| 溧水县| 四会市| 汕尾市| 安岳县| 英德市| 合作市| 满洲里市| 深圳市| 三亚市| 化州市| 阳信县| 拜泉县| 黄陵县| 宜宾市| 海盐县| 江川县| 黎川县| 双辽市| 东明县| 合川市| 鞍山市| 南平市| 鄄城县| 当涂县| 滕州市| 蒙阴县| 湘潭市| 全南县| 玉田县| 仁寿县| 吉林省| 米林县| 五常市| 苍梧县| 峨眉山市| 贺兰县| 兴隆县| 桐庐县|