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)