数据结构与算法(c#实现)系列—广义树(一)
heavenkiller(原创)
广义树和基本树的主要区别就是有任意的度
using system;
using system.collections;
namespace datastructure
{
/// <summary>
/// generaltree 的摘要说明。
/// 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: 在此处添加构造函数逻辑
//
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;
}
}
