Linear table [Stack first-in-first-out] [Queue first-in-first-out]

Source: Internet
Author: User

[Stack first-in-first-out] [Queue first-out]

 

A linear table is the most basic, simple, and commonly used data structure. The relationship between data elements in a linear table is one-to-one, that is, except the first and last data elements, other data elements are connected at the beginning and end. The logical structure of a linear table is simple for implementation and operation. Therefore, the linear table data structure is widely used in practical applications.

 

    Stack first-in-first-out

Public static void QuueMain () {// create a Queue named Queue myQ = new Queue (); myQ. enqueue ("The"); // enter myQ. enqueue ("quick"); myQ. enqueue ("brown"); myQ. enqueue ("fox"); myQ. enqueue (null); // Add null myQ. enqueue ("fox"); // Add duplicate elements // print the number of queues and value Console. writeLine ("myQ"); Console. writeLine ("\ tCount: {0}", myQ. count); // print all values in the queue Console. write ("Queue values:"); PrintValues (myQ); // print the first element in the Queue and remove the Console. writeLine ("(Dequeue) \ t {0}", myQ. dequeue (); // print all values in the queue Console. write ("Queue values:"); PrintValues (myQ); // print the first element in the Queue and remove the Console. writeLine ("(Dequeue) \ t {0}", myQ. dequeue (); // print all values in the queue Console. write ("Queue values:"); PrintValues (myQ); // print the first element in the Queue Console. writeLine ("(Peek) \ t {0}", myQ. peek (); // print all values in the queue Console. write ("Queue values:"); PrintValues (myQ); Console. readLine ();} public static void PrintValues (IEnumerable myCollection) {foreach (Object obj in myCollection) Console. write ("{0}", obj); Console. writeLine ();}

  

Queue (Queue) first-in-first-out

Public static void StackMain () {Stack stack Stack = new stack (); Stack. push ("one"); stack. push ("two"); stack. push ("three"); stack. push ("four"); stack. push ("five"); // print the number of queues and the value Console. writeLine ("Stack"); Console. writeLine ("\ tCount: {0}", stack. count); // print all values in the queue Console. write ("Stack values:"); PrintValues (stack); // print the first element at the top of the queue and remove the Console. writeLine ("(Pop) \ t {0}", stack. pop (); // print all values in the queue Console. write ("Stack values:"); PrintValues (stack); // print the Console, the first element at the top of the queue. writeLine ("(Peek) \ t {0}", stack. peek (); // print all values in the queue Console. write ("stack values:"); PrintValues (stack); Console. readLine ();} public static void PrintValues (IEnumerable myCollection) {foreach (Object obj in myCollection) Console. write ("{0}", obj); Console. writeLine ();}

  

 

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.