Thursday, 1 August 2013

Generic Collection:queue By:Tanuj Kumar


Generic Collection:queue
Queue<t>:

The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
An introduction to DOT NET:
Generic collection: Queue
Generic means it support specific data type (int,float string) 
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.

 .
Generic Collection:queue


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;

namespace queuegeniriccollection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Queue<string> qq = new Queue<string>();
        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");
            }
        }

        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());
        }
        public void show()
        {
            listBox1.Items.Clear();
            foreach (Object obj in qq)
            {
                listBox1.Items.Add(obj);
            }
        }
        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 





            

0 comments:

Post a Comment