Data structures and algorithms (C # implementation) series --- generalized tree (1)

Source: Internet
Author: User

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;

}
}

Related Article

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.