Home  >  Article  >  Backend Development  >  Enqueue and deque in C# Queue class

Enqueue and deque in C# Queue class

PHPz
PHPzforward
2023-09-06 19:09:101351browse

C# Queue 类中的入队和双端队列

The queue collection class is a concept in C# and is included in the System.Collection namespace. Elements are stored in a FIFO queue. The first element added will be the first one out, like people queuing up outside a movie theater to buy tickets.

It has two methods.

  • Enqueue() method adds value
  • Dequeue() method for retrieving values

Enter the team

Add items to the queue.

Queue q = new Queue();
q.Enqueue(“Two”);
q.Enqueue(“One”);

Departure

Return items from the queue.

Queue q = new Queue();
q.Enqueue(“Two”);
q.Enqueue(“One”);
// remove elements
while (q.Count > 0)
   Console.WriteLine(q.Dequeue());

The above is the detailed content of Enqueue and deque in C# Queue class. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete