|
using
System;
using
System.Collections;
class
QueueDemo
{
public
static void Main()
{
//Create an instance of Queue
Queue Q = new Queue();
//Add elements to the Queue using Enqueue() Method
Q.Enqueue("Prasad");
Q.Enqueue("Giri");
Q.Enqueue("Ravi");
//Dequeue() removes and returns the object at the begining of the queue
Console.WriteLine(Q.Dequeue());
//Count determines the number of elements contained in the Queue
//Count will be 2 as we removed the first object from the queue
Console.WriteLine("Count = " + Q.Count);
//Peek() method returns the object at the begining of the queue without
//removing from the queue
Console.WriteLine(Q.Peek());
//The count will still be 2 as the peek() method will not remove the object
//from the queue
Console.WriteLine("Count = " + Q.Count);
//Remove all the items from the Queue using Clear() method
Q.Clear();
}
}
|