Data structure and algorithm (C # implementation) Series---generalized tree (i)

Source: Internet
Author: User
Data | structure and algorithm (C # implementation) Series---generalized tree (i)

Heavenkiller (original)

The main difference between a generalized tree and a basic tree is that it has arbitrary degrees.





Using System;

Using System.Collections;



Namespace Datastructure

{

<summary>

Summary description of the generaltree.

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 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;

}

}





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.