Data Structure and Algorithm (C # Implementation) Series --- Presentation (1)

zhaozj2021-02-16  48

Data Structure and Algorithm (C # Implementation) Series --- Presentation (1)

HEAVENKILLER (original)

This article is mainly for a substantial presentation for the data types of each article. Therefore, I hope that everyone will see this after the analysis of various data structures.

It mainly includes a presentation of the following aspects:

1. Stack. Demonstrate an RPN calculator using a stack

2. Range table. Demonstrate an additional operation of multi-class expressions that use the ranked table

3. Generalized trees. Demonstrate deep traversal and breadth traversal

4. n fork. Demonstrate basic operations such as the generation insertion deletion of the n tok tree

5. Expression tree. Demonstrate an example of using a two-fork tree and stack to translate a suffix expression as a prefix expression of a familiar in everyday

6. AVL tree. Demonstrate basic operation

Using system;

Using system.collections;

Namespace Datastructure

{

///

/// Class1 summary description.

///

Class show

{

///

/// The main entry point for the application.

///

[Stathread]

Static void

Main

(String [] ARGS)

{

//

// Todo: Add code here to start the application

//

While (True)

{

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

Console.writeline ("1.stack ----- rpncalculator");

Console.writeline ("2. SortedList ----- The Addition of Polynomial Realized by SortedList");

Console.writeline ("3.Generaltree ---- Depthtravesal and Breathtraval);

Console.writeline ("4.Narytree");

Console.writeline ("5.ExpressionTree");

Console.writeline ("6.avltree");

Console.writeline ("7.binaryHeap");

Console.Writeline ("exit - exit this programme);

// Test ();

Switch (Console.Readline ())

{

Case "1": // show stack

Showstack_rpncalculator ();

Break;

Case "2": // sortedList

ShowsortlishedList_PolyNomial ();

Break;

Case "3":

Showgeneraltree_travel ();

Break;

Case "4":

ShownaryTree (); // Demonstrate ATTACH and DETACH

Break;

Case "5":

ShowExpressionTree ();

Break;

Case "6":

Showavltree ();

Break;

Case "7":

Showbinaryheap ();

Break;

Case "exit":

Return;

DEFAULT:

Break;

}

}

}

Public static void showbinaryHeap ()

{

// Construct a binary react, including 2, 4, 6, 8, 10, 12binaryHeap Bheap = New BinaryHeap (10);

BHEAP.Enqueue (12);

Bheap.enqueue (10);

Bheap.enqueue (8);

Bheap.enqueue (6);

BHEAP.Enqueue (4);

Bheap.enqueue (2);

// Test Dequeue ();

While (BHEAP.COUNT! = 0)

{

Console.writeline (BHEAP.DEQUEUEMINE (). TOSTRING ());

}

}

Public static void showavltree ()

{

Avltree TestAvl = New Avltree (5);

TestaVl.insert (1);

TestaVl.insert (3);

TestaVl.insert (7);

TestaVl.insert (8);

TestaVl.insert (9);

TestaVl.insert (10);

TestaVl.insert (11);

PrintVisitor VIS = New PrintVisitor ();

Tree.inorder Invis = New DataStructure.tree.inorder (VIS);

Testavl.depthfirsttraversal (Invis);

}

Public static void showexpressionTree ()

{

ExpressionTree.PostFixToinfix ();

}

Public static void shownaryTree ()

{

// Construct a trigemine, see Figure 1-2

Narytree a = new Narytree (3, "a");

Narytree B = New Narytree (3, "B");

Narytree C = New Narytree (3, "C");

Narytree D = New NaryTree (3, "D");

Narytree E = New Narytree (3, "e");

B.attachSubtree (1, d);

B.attachSubtree (2, e);

A.attachSubtree (1, b);

A.attachSubtree (3, c);

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

Console.WriteLine ("Scea Traverse");

PrintVisitor VIS = New PrintVisitor ();

A.BreadthfirstTraversal (VIS); // Scene Traverse

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

Tree.Preorder Previsit = New DataStructure.tree.preorder (VIS);

A.Depthfirsttraversal (Previsi);

Console.writeline ("Sequence Traverse");

Tree.postorder Postvisit = New DataStructure.tree.postorder (VIS);

A.Depthfirsttraversal (Postvis);

Console.writeline ("Southern Subcommitte";

Tree.inorder Invisit = New DataStructure.tree.inorder (VIS);

A.Depthfirsttraversal (Invisit);

}

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

New Post(0)