Use C # To implement the data structure-tree (1)

Source: Internet
Author: User

Data structures and algorithms (C # implementation) series --- tree (1)
Heavenkiller (original)
First, let's define the tree:
A tree is a finite, non-empty node set,
T = {r} or T1 or T2 or... Or Tn
It has the following properties:
1. the node r specified in the set is called the root node of the tree.
2. The remaining nodes can be divided into n subsets, T1, T2 ,... Tn (n> = 0), where each subset is a tree.
 
Other tree definitions, such as degree, leaf, and higher, are available everywhere.
 
One of the main features of a tree is traversal, which can be divided into deep traversal and breadth traversal.
Here, DepthFirstTravesal () and WidthFirstTravesal () are implemented respectively ()
Deep traversal is divided into pre-order traversal, middle-order traversal, and post-order traversal.
This is achieved by using the adapter technology.
 
Using System;
Using System. Collections;
 
Namespace DataStructure
{
/// <Summary>
/// Tree summary.
/// When traverse, traversaltype can't be changed, or throw a exception
/// Supports enumeration, comparison, and deep Replication
/// </Summary>
Public abstract class Tree: IEnumerable, IComparable
{
Public Tree ()
{
//
// TODO: add the constructor logic here
//

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.