Data structures and algorithms (C # implementation) series-demonstration (II)

Source: Internet
Author: User

Data structures and algorithms (C # implementation) series-demonstration (II)

Heavenkiller (original)

Public static void ShowGeneralTree_travel ()

{

IEnumerator tmpIEnum;

Tree. TraversalType travelType = 0;

 

// --------------------- Prompt ----------------------------

Console. WriteLine ("please choose a No. of a item you want to travel :");

Console. WriteLine ("1. BreadthFirst ----- span traversal ");

Console. WriteLine ("2. PreDepthFirst ----- forward traversal ");

Console. WriteLine ("3. InDepthFirst ---- middle-order traversal ");

Console. WriteLine ("4. PostDepthFirst ---- post-order traversal ");

Switch (Console. ReadLine ())

{

Case "1": // Show Stack

TravelType = Tree. TraversalType. Breadth;

Console. WriteLine ("span traversal ");

Break;

Case "2": // SortedList

TravelType = Tree. TraversalType. PreDepth;

Console. WriteLine ("Forward traversal ");

Break;

Case "3 ":

TravelType = Tree. TraversalType. InDepth;

Console. WriteLine ("sequential traversal ");

Break;

Case "4 ":

 

 

TravelType = Tree. TraversalType. PostDepth;

Console. WriteLine ("sequential traversal ");

Break;

Default:

Break;

}

// Construct a generalized tree generaltree

GeneralTree A = new GeneralTree ("");

GeneralTree B = new GeneralTree ("B ");

GeneralTree C = new GeneralTree ("C ");

GeneralTree D = new GeneralTree ("D ");

GeneralTree E = new GeneralTree ("E ");

GeneralTree F = new GeneralTree ("F ");

A. AttackSubtree (B );

A. AttackSubtree (C );

B. AttackSubtree (D );

B. AttackSubtree (E );

A. AttackSubtree (F );

// Show the operation

Console. WriteLine ("A. AttackSubtree (B )");

Console. WriteLine ("A. AttackSubtree (C )");

Console. WriteLine ("B. AttackSubtree (D )");

Console. WriteLine ("B. AttackSubtree (E )");

Console. WriteLine ("A. AttackSubtree (F )");

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

A. SetTraversalType (travelType); // you can specify the traversal type.

TmpIEnum = A. GetEnumerator ();

 

// Console. WriteLine ("begin to depthfist travel :");

While (tmpIEnum. MoveNext ())

{

Console. WriteLine (t

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.