Data structure and algorithm (C # implementation) Series---demo (i.)

Source: Internet
Author: User
Tags exit expression insert rpn calculator sort
Data | structure | algorithm data structure and algorithm (C # implementation) Series---demo (i.)

Heavenkiller (original)

This article is mainly for the future of the data types to carry out a substantive demonstration. Therefore, I hope that we have a specific look at the various data structure analysis and then look at this article.

Mainly includes the following several aspects of the demonstration:

1. Stack. Demonstrates a RPN calculator that uses a stack

2. Sort table. Demonstrates an addition operation that uses a sort table to do polynomial expressions

3. Generalized tree. Demonstrates depth traversal and breadth traversal

4. N Fork Tree. Demonstrates the basic operations of N-fork tree Generation Insert Deletion

5. An expression tree. Demonstrates an example of using a binary tree and a stack to translate a suffix expression into a familiar infix expression in everyday life.

6. AVL Tree. Demonstrates basic operations





Using System;

Using System.Collections;



Namespace Datastructure

{

<summary>

Summary description of the CLASS1.

</summary>

Class Show

{

<summary>

The main entry point for the application.

</summary>

[STAThread]

static void Main (string[] args)

{

//

TODO: Add code here to start the application

//

while (true)

{

Console.WriteLine ("Please choose a" 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

Showsortedlist_polynomial ();

Break

Case "3":

Showgeneraltree_travel ();

Break

Case "4":

Shownarytree ()///demo of attach and detach of a three-pronged tree

Break

Case "5":

Showexpressiontree ();

Break

Case "6":

Showavltree ();

Break

Case "7":

Showbinaryheap ();

Break

Case "Exit":

Return

Default

Break

}

}



}

public static void Showbinaryheap ()

{

Constructs a binary heap that contains 2,4,6,8,10,12

Binaryheap 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.dequeuemin (). 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 three-pronged tree, 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 ("Breadth Traversal");

Printvisitor vis=new printvisitor ();



A.breadthfirsttraversal (VIS);//Breadth traversal



Console.WriteLine ("Pre-sequence traversal");

Tree.preorder previsit=new DataStructure.Tree.PreOrder (VIS);

A.depthfirsttraversal (Previsit);



Console.WriteLine ("subsequent traversal");

Tree.postorder postvisit=new DataStructure.Tree.PostOrder (VIS);

A.depthfirsttraversal (Postvisit);



Console.WriteLine ("Sequence Traversal");

Tree.inorder invisit=new DataStructure.Tree.InOrder (VIS);

A.depthfirsttraversal (Invisit);





}


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.