The N-fork tree has the same degree of every node as n
Using System;
Using System.Collections;
Namespace Datastructure
{
<summary>
Summary description of the narytree. -----N-Fork Tree
</summary>
public class Narytree:tree
{
Member variables
PRotected Object key;
protected UINT Degree;
Protected ArrayList treelist=new ArrayList ();
protected UINT height=0;//temporarily defaults to 0
Create a empty tree whose attribute of degree is _degree
Public Narytree (UINT _degree)
{
//
TODO: Add constructor logic here
//
This.key=null;
This.degree=_degree;
This.treelist=null;
}
Construct an n-forked tree with a leaf node
Public Narytree (UINT _degree,object _key)
{
This.key=_key;
This.degree=_degree;
This.treelist=new ArrayList ();
this.treelist.capacity= (int) _degree;
for (int i=0;i<this.treelist.capacity;i++)
{
THIS.TREELIST.ADD (this. Getemptyinstance (_degree));
}
}
//-----------------------------------------------------------------
Protected virtual Object Getemptyinstance (UINT _degree)
{return new Narytree (_degree);}
//-------------------------------------------------------------------
Judge whether the empty tree
public override bool IsEmpty ()
{return this.key==null;}
Determine if it is a leaf node. If that is not an empty tree and each Shang tree is an empty tree, the leaf node
public override bool IsLeaf ()
{
if (IsEmpty ())
return false;
for (UINT i=0;i<this.degree;i++)
{
if (!) ( This[i]. IsEmpty ()))
return false;
}
return true;
}
-----------------------------------inherited Attributes---------------------------------
public override Object Key
{
Get
{
return this.key;
}
}
Indexing device
public override tree This[uint _index]
{
Get
{
if (_index>=this.degree)
throw new Exception ("My:out of index!"); /If out of bounds, throw an exception
if (this. IsEmpty ())
Return null;//If it is an empty tree, the indexer returns a null
return (tree) this.treelist[(int) _index];
}
Set
{
this.treelist[(int) _index]=value;
}
}