Set> queue

Source: Internet
Author: User

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 );
}
}

}


}

 

 

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.