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