資料結構與演算法(C#實現)系列---廣義樹(一) (轉)

themoney發表於2007-09-30
資料結構與演算法(C#實現)系列---廣義樹(一) (轉)[@more@]

  資料結構與演算法(實現)系列---廣義樹(一):namespace prefix = o ns = "urn:schemas--com::office" />

  Heavenkiller(原創)

廣義樹和基本樹的主要區別就是有任意的度

using System;

using System.Collections;

namespace DataStructure

{

  ///

  /// GeneralTree 的摘要說明。

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

  /// use ArrayList to replace ListAsLinkedList

  ///

  public class GeneralTree:Tree

  {

  protected key=null;

  protected uint degree=0;

  //protected uint height=0;

  protected ArrayList treeList=new ArrayList();

  public GeneralTree(object _objKey)

  {

  //

  // TODO: 在此處新增構造邏輯

  //

  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 overr 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;

  }

  }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10794571/viewspace-974270/,如需轉載,請註明出處,否則將追究法律責任。

相關文章