Thursday, July 1, 2010

COLLECTIONS INTERFACE USING QUEUE

Represents a first-in, first-out collection of objects.

Namespace: System.Collections

the .NET Framework provides the serialized Queue class that implements both the ICollection and the IEnumerable interfaces.
To add value in queue , Enqueue method is used.
Peek()-the first item added to a queue stays in front of all others that would be added.
The process of removing an item from a queue is called "dequeue".


Example Programe

using System;
using System.Collections;
class queue1
{
public static void Main(string[] args)
{
Queue q1=new Queue();
q1.Enqueue(55);
q1.Enqueue(65);
q1.Enqueue(75);
q1.Enqueue(85);

Console.WriteLine(q1.Dequeue());
Console.WriteLine(q1.Peek());
Console.WriteLine(q1.Dequeue());
}
}

No comments:

Post a Comment