C # Queued Queue

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;namespaceQueue Test {classProgram {Static voidMain (string[] args) {Queue<string> strlist =Newqueue<string>(); ///adding elements to a queueStrlist.enqueue ("element 1"); Strlist.enqueue ("element 2"); Strlist.enqueue ("element 3"); ///traversing elements            foreach(varIteminchstrlist)            {Console.WriteLine (item); }            ///Captain LengthConsole.Write ("Queue Length---");            Console.WriteLine (Strlist.count); ////Remove the first added elements, and delete, fully reflect the first -in-a-out characteristics of the queue///If there are no elements in the queue, an exception is thrown            //string mes = Strlist.dequeue (); //Console.WriteLine (MES);            ///Remove The elements that were first queued, but do not delete            stringMes =Strlist.peek (); Console.Write ("remove elements from the team header without removing them----");            Console.WriteLine (MES); ///traverse Queue, still three elementsConsole.WriteLine ("the remaining elements of the queue are---"); foreach(varIteminchstrlist)            {Console.WriteLine (item); }            ///directly obtains an element in the queue,///throws an exception if the index is out of boundsConsole.Write ("gets the 2nd element in a queue----"); strings = Strlist.elementat (2);            Console.WriteLine (s); ///directly obtains an element in the queue,///if the index is out of bounds, NULL is returned, but no exception is thrownConsole.Write ("gets the 5th element in a queue-----"); Console.WriteLine (Strlist.elementatordefault (5)); Console.Write ("gets the 1th element in a queue-----"); Console.WriteLine (Strlist.elementatordefault (1)); ///Remove The elements that were first queued, but do not delete              stringPop =Strlist.dequeue (); Console.Write ("remove elements from the team head----");              Console.WriteLine (MES); ///traverse the queue for 2 elementsConsole.WriteLine ("the remaining elements of the queue are---"); foreach(varIteminchstrlist)              {Console.WriteLine (item);          } console.readkey (); }    }}

C # Queued Queue

Related Article

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.