O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

19.4. Queue

As the name implies, a Queue encapsulates a standard FIFO abstract data type. Queues are useful for storing objects to be processed in the order that they are received. The three most commonly used methods of a Queue are Peek, Enqueue, and Dequeue. Like an ArrayList, the capacity of a Queue object changes automatically as more objects are inserted.

The program below demonstrates how Queue can be used. The output is interspersed with the code to show the outputs of the different sections.

 1: using System;
 2: using System.Collections;
 3:
 4: public class TestClass{
 5:   public static void Main(){
 6:
 7:     Queue q = new Queue();
 8:
 9:     // Using Enqueue 10: q.Enqueue("A"); 11: q.Enqueue("B"); 12: q.Enqueue("C"); 13: q.Enqueue("D"); 14: q.Enqueue("E"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required