明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

數(shù)據(jù)結(jié)構(gòu)與算法(C#完成)系列---廣義樹(shù)(一)

[摘要]數(shù)據(jù)結(jié)構(gòu)與算法(C#實(shí)現(xiàn))系列---廣義樹(shù)(一)Heavenkiller(原創(chuàng))廣義樹(shù)和基本樹(shù)的主要區(qū)別就是有任意的度using System;using System.Collections;namespace DataStructure /// <summary> ...

數(shù)據(jù)結(jié)構(gòu)與算法(C#實(shí)現(xiàn))系列---廣義樹(shù)(一)

Heavenkiller(原創(chuàng))

廣義樹(shù)和基本樹(shù)的主要區(qū)別就是有任意的度

using System;
using System.Collections;
namespace DataStructure

{
     /// <summary>

     /// GeneralTree 的摘要說(shuō)明。

     /// general tree is a tree which has a arbitrary degree and no empty tree

     /// use ArrayList to replace ListAsLinkedList

     /// </summary>

     public class GeneralTree:Tree

     {

         protected object key=null;

         protected uint degree=0;

         //protected uint height=0;

 

         protected ArrayList treeList=new ArrayList();

 

         public GeneralTree(object _objKey)

         {

              //

              // TODO: 在此處添加構(gòu)造函數(shù)邏輯

              //

 

              key=_objKey;

              degree=0;

         //   height=0;

              ArrayList treeList=new ArrayList();

         }

 

         public virtual void AttackSubtree(GeneralTree _gTree)

         {

              this.treeList.Add(_gTree);

              ++degree;

         }

         public virtual GeneralTree DetachSubtree(GeneralTree _gTree)

         {

             

              this.treeList.Remove(_gTree);

              degree--;

             

              return _gTree;//?????  how to remove ,reference or object????

         }

 

         public override Tree this[uint _index]

         {

              get

              {

                   if(_index>=this.degree)

                       throw new Exception("my:out of index");

                   return (Tree)treeList[(int)_index];

              }

              set

              {
                   treeList[(int)_index]=value;

              }
         }