ITPub博客

首页 > 应用开发 > IT综合 > 数据结构与算法(C#实现)系列---广义树(一) (转)

数据结构与算法(C#实现)系列---广义树(一) (转)

原创 IT综合 作者:themoney 时间:2007-09-30 17:13:02 0 删除 编辑
数据结构与算法(C#实现)系列---广义树(一) (转)[@more@]

  数据结构与算法(C#实现)系列---广义树(一)XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office: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 object 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 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;

  }

  }


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10794571/viewspace-974270/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    119
  • 访问量
    357055