Define QUEUE Class

Posted on Updated on

Untitled16

QUEUE Class

It is a first-in, first out (FIFO) type collection of object. It is used when a first-in, first-out type of access of items is required. When items are added in the list, it is called enqueue, and when removed it is called dequeue.

Methods and Properties of the Queue Class

Property Description

Count Gets the number of elements contained in the Queue.

Sr.No.                                   Methods

     1                                             public virtual void Clear();

     2                                             public virtual bool Contains(object obj);

     3                                             public virtual object Dequeue();

     4                                             public virtual void Enqueue(object obj);

     5                                             public virtual object[] ToArray();

     6                                             public virtual void TrimToSize();

Example

using System;

using System.Collections;

namespace CollectionsApplication

{

class Program

{

static void Main(string[] args)

{

Queue q = new Queue();

q.Enqueue(‘A’);

q.Enqueue(‘M’);

q.Enqueue(‘G’);

q.Enqueue(‘W’);

Console.WriteLine(“Current queue: “);

foreach (char c in q) Console.Write(c + ” “);

Console.WriteLine();

q.Enqueue(‘V’);

q.Enqueue(‘H’);

Console.WriteLine(“Current queue: “);

foreach (char c in q) Console.Write(c + ” “);

Console.WriteLine();

Console.WriteLine(“Removing some values “);

char ch = (char)q.Dequeue();

Console.WriteLine(“The removed value: {0}”, ch);

ch = (char)q.Dequeue();

Console.WriteLine(“The removed value: {0}”, ch);

Console.ReadKey();

}

}

}

*****************************************************************************************************

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.
Helpline: 9814666333, 8699444666
Email: info@technocampus.co.in

Please fill the form and we shall contact you soon.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s