Queue queue: first-in-first-out, first-in-first-out, and then-out.
Set> queue> Create queue
The system. Collections. Queue class provides four types of overloaded constructors.
Code Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. collections;
Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
// Use the default constructor to construct the queue
Queue Qu = new Queue ();
Qu. enqueue ("queue element 1 ");
Qu. enqueue ("queue element 2 ");
Qu. enqueue (null );
// Use the class instance that implements the icollection interface, which is an array list to construct the queue
Queue qu2 = new Queue (New String [5] {"queue element 1", "queue element 2", "queue element 3", "queue element 4 ", "queue element 5 "});
// Use the initial capacity of 20 elements to construct the queue.
Queue qu3 = new Queue (20 );
// Use the initial capacity of 20 elements and the proportional factor of 2 to construct the queue.
Queue qu4 = new Queue (20, 2 );
}
}
}
The proportional factor indicates that the current capacity is 5. If you want to expand the capacity to 10 at a time when the capacity expansion is large, the proportional factor is 2.
The default capacity of queue is 32 elements.
Set> queue> element to join and exit
Code Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. collections;
Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
Queue Qu = new Queue ();
Qu. enqueue ("element 1 ");
Qu. enqueue ("element 2 ");
Qu. enqueue ("element 3 ");
Qu. enqueue ("element 4 ");
Qu. enqueue ("element 5 ");
Console. writeline ("the original queue is as follows :");
Displayresult (qu );
Qu. dequeue ();
Console. writeline ("after removing the first element ");
Displayresult (qu );
Qu. dequeue ();
Console. writeline ("after removing the second element ");
Displayresult (qu );
Console. Readline ();
}
Static void displayresult (queue qu)
{
Foreach (Object s in Qu)
{
Console. writeline (s );
}
}
}
}