illustrates the use of a Queue : Queue : Collections Data Structure C# Source Code


Custom Search

C# Source Code » Collections Data Structure » Queue »

 

illustrates the use of a Queue









    

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example11_10.cs illustrates the use of a Queue
*/

using System;
using System.Collections;

public class Example11_10
{

  public static void Main()
  {

    // create a Queue object
    Queue myQueue = new Queue();

    // add elements to myQueue using the Enqueue() method
    myQueue.Enqueue("This");
    myQueue.Enqueue("is");
    myQueue.Enqueue("a");
    myQueue.Enqueue("test");

    // display the elements in myQueue
    foreach (string myString in myQueue)
    {
      Console.WriteLine("myString = " + myString);
    }

    // get the number of elements in myQueue using the
    // Count property
    int numElements = myQueue.Count;

    for (int count = 0; count < numElements; count++)
    {

      // examine an element in myQueue using Peek()
      Console.WriteLine("myQueue.Peek() = " +
        myQueue.Peek());

      // remove an element from myQueue using Dequeue()
      Console.WriteLine("myQueue.Dequeue() = " +
        myQueue.Dequeue());

    }

  }

}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Collections Data Structure
» Queue