Queuing queue FIFO advanced first out stack stack filo advanced post-out

Source: Internet
Author: User

Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Namespace consoleapplication1{class Program {static void Main (string[] args) {//queue is characterized by first            In-first-out queue<string> Queue = new queue<string> (); Queue.   Enqueue ("Zhang San");            The queue adds the object to the end of the system.collections.generic.queue<t>. Queue.            Enqueue ("John Doe"); Queue.            Enqueue ("Harry"); int queuecount = queue. Count (); Returns the number of elements in a sequence, string name = Queue. Dequeue ();            The team removed the elements from the first team and returned the removed elements. Console.WriteLine (name); Output "Zhang San" name = queue. Dequeue (); Because "Zhang San" has been removed. So now is "John Doe" is in the team first Console.WriteLine (name); Output "John Doe" name = queue. Dequeue ();            Because "John Doe" is also removed, so there is only Harry left in the queue. Console.WriteLine (name); Output "Harry"//------------------------------------------------------------//stack is characterized by advanced back-out (understand the Yes, not much) stack<string&Gt            stack = new stack<string> (); Stack. Push ("Zhang San");            into the stack, inserting the object into the top of the system.collections.generic.stack<t>. Stack.             Push ("John Doe"); Stack.            Push ("Harry"); int stackcount= stack. Count (); Returns the number of strings in the stack name1 = stack. Pop (); Out of the stack.            Removes the element from the top of the stack and returns the removed element. Console.WriteLine (name); Output: "Harry" name1 = stack.            Pop (); Console.WriteLine (name1);//output: "John Doe" name1 = stack.            Pop (); Console.WriteLine (name1);//output: "Zhang San"//name1 = stack. Peek ();        This is the object that returns the top of the stack, but does not remove the Console.readkey (); }    }}

  

Queuing queue FIFO advanced first out stack stack filo advanced post-out

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.