Data structure and algorithm (C # implementation) Series---n-fork Tree (ii)

Source: Internet
Author: User
Data | structure | algorithm data structure and algorithm (C # implementation) Series---n-fork Tree (ii)

Heavenkiller (original)

public override UINT Degree

{

Get

{

return this.degree;

}

}



//-------------------------------------------------------------------------------------



For empty tree nodes only.

public virtual void Attachkey (object _obj)

{

if (! IsEmpty ())

throw new Exception ("My:this node must being a empty tree node!");

This.key=_obj;

This.treelist=new ArrayList ()//generates a degree long array and initializes it to an empty tree

this.treelist.capacity= (int) this.degree;



for (int i=0;i<this.degree;i++)

{

Treelist.add (New Narytree (This.degree));

}

/*

foreach (Object tmpobj in This.treelist)

{

Tmpobj=new Narytree (This.degree);

}

*/

}

Used only for leaf nodes, turning leaf nodes into an empty node, and returning the reference to the leaf node key word

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;

}

Connects the subtree to the NUM node of the specified tree, provided that the node must be an empty node and has the same degree, otherwise throwing 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 they should have the same");

This[num-1]=_narytree;

}

Defines only a non-empty tree, deletes its Shang tree from a given tree and connects an empty tree with the same degree, and returns the subtree reference that was deleted

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;

((Narytree) this[num-1]). Treelist=null;



return this;

}



//----------------------------------------------------------------------------------





}

}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.