Queue:non generic collection
An introduction to DOT NET:
Non generic collection: Queue
The non-generic collection classes store data of type Object.
queue is FIFO first come first served .
Here queue is used to save data and retrieved it in FIFO manner.
You can run program and see the working procedure of it.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace queuecollectionprogram
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
label1.Text = "";
}
Queue
qq = new Queue();
private
void textBox1_TextChanged(object sender, EventArgs
e)
{
label1.Text = "";
}
private
void button1_Click(object
sender, EventArgs e)
{
label1.Text = "";
if
(textBox1.Text == "")
{
MessageBox.Show("Enter value in textbox");
}
else
{
qq.Enqueue(textBox1.Text);
show();
MessageBox.Show(textBox1.Text
+ " inserted");
}
}
public void show()
{
listBox1.Items.Clear();
foreach
(Object obj in
qq)
{
listBox1.Items.Add(obj);
}
}
private
void button2_Click(object
sender, EventArgs e)
{
if
(qq.Count <= 0)
{
MessageBox.Show("queue is emplty");
}
else
{
label1.Text =
qq.Dequeue().ToString();
show();
}
}
private
void button3_Click(object
sender, EventArgs e)
{
label1.Text = "";
if
(qq.Count <= 0)
{
MessageBox.Show("queue is empty");
}
else
{
label1.Text = "peek element is:" +
qq.Peek().ToString();
show();
}
}
private
void button5_Click(object
sender, EventArgs e)
{
label1.Text = "";
MessageBox.Show("Total queue element is " + qq.Count.ToString());
}
private
void button4_Click(object
sender, EventArgs e)
{
label1.Text = "";
if
(qq.Count <= 0)
{
MessageBox.Show("queue is empty");
}
else
{
if
(qq.Contains(textBox2.Text))
{
MessageBox.Show("available");
}
else
{
MessageBox.Show("Not available");
}
}
}
}
}
Posted By:Tanuj Kumar
On:Shareyourconscience
Comments
Post a Comment