Data Structure and Algorithm (C # Implementation) Series --- Demonstration (2)

zhaozj2021-02-16  50

Data Structure and Algorithm (C # Implementation) Series --- Demonstration (2)

HEAVENKILLER (original)

Public static void showgeneraltree_travel ()

{

IEnumerator TMPIENUM;

Tree.traversalType TravelType = 0;

//---------------------prompt-------------------------- -

Console.writeline ("please choise a the no. of a item you want to travel:");

Console.writeline ("1.Breadthfirst ----- Scene");

Console.writeline ("2.Predepthfirst ----- pre-sequence traversal");

Console.writeline ("3.indepthfirst ---- Sedential Traverse");

Console.writeLine ("4.PostDepthfirst ---- Rear Sequence Traverse");

Switch (Console.Readline ())

{

Case "1": // show stack

TravelType = tree.traversaltype.breadth;

Console.WriteLine ("Scea Traverse");

Break;

Case "2": // sortedList

TravelType = tree.traversaltype.predepth;

Console.writeLine ("pre-sequence traversal");

Break;

Case "3":

TravelType = tree.traversaltype.indepth;

Console.writeline ("Southern Subcommitte";

Break;

Case "4":

TravelType = tree.traversaltype.postDepth;

Console.writeline ("Sequence Traverse");

Break;

DEFAULT:

Break;

}

// Construct a generalized tree generaltree

Generaltree a = new generaltree ("a");

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); // Set traversal type

Tmpienum = a.Getenumerator ();

//Console.writeline ("Begin to Depthfist Travel:");

While (tmpienum.movenext ())

{

Console.writeLine (Tmpienum.current.toString ());

}

}

Public static void showstack_rpncalculator ()

{

// read a expression String and Push Every Character INTO The Stack in Queue.

Console.Writeline ("this is Performance for Stack, You CAN Input A String Like this '123 * ', Then Subprogramme CAN Compute It and get the result '7', this is rpn calculator.")

Console.WriteLine ("Please Input A Expression String:");

String strexpression = console.readline ();

Char [] tmpchars = strexpression.tochararray (0, strexpression.length);

Stack stackrpn = new stack ();

INT NUMA, NUMB;

Foreach (Char Tmp in TmpChars)

{

Switch (TMP)

{

Case '*':

Numa = (int) stackrpn.pop ();

NUMB = (int) stackrpn.pop ();

StackRPN.PUSH (Numa * Numb);

Break;

Case ' ':

Numa = (int) stackrpn.pop ();

NUMB = (int) stackrpn.pop ();

StackRPN.PUSH (NUMA NUMB);

Break;

DEFAULT:

Stackrpn.push (int32.parse (tmp.tostring ())));

Break;

}

}

Console.writeline ("The Result IS: {0}", stackrpn.pop (). TOSTRING ());

}

转载请注明原文地址:https://www.9cbs.com/read-23125.html

New Post(0)