Data Structure and Algorithm (C # Implementation) Series --- N Fork Tree (2)
HEAVENKILLER (original)
Public Override uint Degree
{
get
{
Return this.degree;
}
}
/ / -------------------------------------------------------------------------------------------- -------------------------------------
// only for empty tree nodes
Public Virtual Void AttachKey (Object_Obj)
{
IF (! iSempty ())
Throw New Exception ("My: this node must be a empty tree node!");
THIS.KEY = _OBJ;
this.treeList (); // Generate an array of Degree, and initialize it to empty tree
THIS.TREELIST.capacity = (int) this.degree;
For (INT i = 0; I { Treelist.add (New Narytree (this.degree); } / * Foreach (Object Tmpobj in this.treelist) { Tmpobj = new narytree (this.degree); } * / } // only for the leaf node, turn the leaf node to a hollow node, and return to the keyword of the leaf node keyword Public Virtual Object DetachKey () { IF (! isleaf ()) Throw New Exception ("My: this node must be a leaf node!"); Object result = this.key; // store this Leaf Node Temporary THIS.KEY = NULL; THIS.TREELIST = NULL; Return Result; } // Connect the child to the Nth Num of the designated tree, the premise is that this node must be a hollow node, and the degree is the same, otherwise it will throw an exception. Public Virtual Void AttachSubtree (uint num, narytree _narytree) { IF (this.isempty ()) Throw new Exception ("My: IT CAN't Be a Empty Tree!"); IF (! (this [NUM-1] .isempty ()) | this.degree! = _ narytree.degree) Throw new Exception ("My: this [i-1] Must Be Empty and The Should Have The Same Degree!"); THIS [NUM-1] = _ NARYTREE } // Only non-empty tree definition, remove it from the given tree and connect the same empty tree, the degree of the degree, and return the deleted sub-tree reference Public Virtual Narytree DetachSubtree (uint num) { IF (iSempty ()) Throw new Exception ("My: IT CAN't Be Empty!"); Narytree tmptree = this; (NARYTREE) THIS [NUM-1]). Key = NULL; (Naretree). [NUM-1]). Treelist = NULL; Return this; } / / -------------------------------------------------------------------------------------------- ----------------------------------} }