C # queue (queue)

Source: Internet
Author: User

Queue: A data operation that simulates a queue.

For example, queuing up for a ticket is a queue operation, and later people are in the back row, the first comes in front of the person, and the ticket request is processed first. In order to simulate the operation of the queue, queue adds the following restrictions based on ArrayList

1. The element takes the first-in, first-out mechanism (Fifo,first in the first out), that is, the element entering the queue must first leave the queue. The first element to enter is called the team head element. • The element can only be added to the end of the queue (called the queue) and is not allowed to be inserted somewhere in the middle. In other words, The Insert method in ArrayList is not supported

2. Only the elements of the team head can be deleted (called out-of-band), not directly to the queue of non-team head elements to ensure that the FIFO mechanism is removed. In other words, the Remove method in ArrayList is not supported.

3. Access to non-team header elements of the queue is not allowed directly. In other words, indexing in ArrayList is not supported , only traversal access is allowed

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;namespacerooxml{ Public classMain { Public Static voidMain () {Queue<A> que =NewQueue<a> (); Que.            Clear (); Que. Enqueue (NewA () {k= One, v="I am FW"}); Que. Enqueue (NewA () {k=6, v="I am"}); Que. Enqueue (NewA () {k= -, v="I am Cvjar"}); foreach(varRinchque)            {Console.WriteLine (R.K); } Console.WriteLine (Que. Peek (). K+" "+ Que. Peek (). v);//Stack Top ValueConsole.WriteLine (Que.            Count);            Console.WriteLine (); Que.   Dequeue (); //remove top of stack            foreach(varRinchque) {                if(R.K = = -) {Console.WriteLine (R.K);        }} Console.WriteLine (); }    }    classa{ Public intk{Get;Set;}  Public stringv{Get;Set; } }}

C # queue (queue)

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.