Data structures and algorithms (C # implementation) series --- generalized tree (1)
Heavenkiller (original)
The main difference between a generalized tree and a basic tree is that there is an arbitrary degree.
Using System;
Using System. Collections;
Namespace DataStructure
{
/// <Summary>
/// Abstract description of 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: add the constructor logic here
//
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;
}
}