Data Structure and Algorithm (C # Implementation) Series --- Generalized Tree (1)
HEAVENKILLER (original)
The main difference between the generalized tree and the basic tree is any degree
Using system;
Using system.collections;
Namespace Datastructure
{
///
/// generaltree's summary description.
/// 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 deterree = 0;
// protected uint heiGHT = 0;
protected arraylist treelist = new arraylist ();
Public generaltree (Object _objKey)
{
//
// TODO: Add constructor logic here
//
Key = _objKey;
Degree = 0;
// heiGHT = 0;
ArrayList treelist = new arraylist ();
}
Public Virtual Void Attacksubtree (Generaltree_Gtree)
{
this.treeelist.add (_gtree);
Degree;
}
Public Virtual GeneRaltree DetachSubtree (Generaltree_Gtree)
{
this.treeelist.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;
}
}