Collection>Queue>Create queue
The class provides four overload constructors.
using ;
using ;
using ;
using ;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Construct Queue using the default constructor
Queue qu = new Queue();
("Quote Element One");
("Quote Element Two");
(null);
//Use a class instance that implements the ICollection interface, here is an array list, construct the Queue
Queue qu2 = new Queue(new string[5] { "Queue Element One", "Queue Element Two", "Queue Element Three", "Queue Element Four", "Queue Element Five" });
//Construct Queue with initial capacity of 20 elements.
Queue qu3 = new Queue(20);
//Construct Queue using the initial capacity of 20 elements and the equality factor of 2.
Queue qu4 = new Queue(20, 2);
}
}
}
The equal ratio factor means that the current capacity is 5. If the capacity is expected to expand to 10 at one time, the equal ratio factor is 2.
The default capacity of Queue is 32 elements.
Collection>Queue>Entering and dequeuing elements
using ;
using ;
using ;
using ;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Queue qu = new Queue();
("Element One");
("Element Two");
("Element Three");
("Element Four");
("Element Five");
("The original queue looks like this:");
DisplayResult(qu);
();
("After removing the first element");
DisplayResult(qu);
();
("After removing the second element");
DisplayResult(qu);
();
}
static void DisplayResult(Queue qu)
{
foreach (object s in qu)
{
(s);
}
}
}
}