Sunday, 21 July 2013

Non Generic Collection:Queue


Non Generic Collection:QueueQueue: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.

Non 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;
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



Read More
Posted on 9:07:00 pm
Categories:

Nongeneric Collection:Stack By:Tanuj Kumar

Nongeneric Collection:Stack

stack:non generic collection

The System.Collections namespace contains interfaces and classes that define Non generic collections, which allow users to  collections.
An introduction to DOT NET:
Non Generic collection: Stack
Stackis LIFO Last in first out.
Here stack is used to save data and retrieved it in LIFO manner.
You can run program and see the working procedure of it.
Nongeneric Collection:Stack



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 stackcollection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Stack st = new Stack();
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text =="")
            {

                MessageBox.Show("enter value in textbox");
            }
            else
            {
                st.Push(textBox1.Text);
                MessageBox.Show("inserted");
            }
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (st.Count > 0)
            {
                Object obj = new Object();
                obj = st.Pop();
                MessageBox.Show(obj.ToString());
            }
            else {

                MessageBox.Show("no element in stack");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (st.Count <= 0)
            {

                MessageBox.Show("stack is empty");
            }
            else
            {
                Object obj = new Object();
                obj = st.Peek();
                MessageBox.Show(obj.ToString());
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (st.Count <=0)
            {

                MessageBox.Show("stack is empty");
            }
            else
            {
                if (st.Contains(textBox2.Text))
                {

                    MessageBox.Show("available");
                }
                else
                {
                    MessageBox.Show("not available");
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(st.Count.ToString());
        }
    }
}
Read More
Posted on 9:07:00 pm
Categories:

Nongeneric Collection:Hash Table By:Tanuj Kumar


Nongeneric Collection:Hash Table


Hash table :Nongeniric collection
Nongeneric Collection:Hash Table



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 hashtableprogram
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        String s;
        Hashtable ht = new Hashtable();


        private void button1_Click(object sender, EventArgs e)
        {
            ht.Add(textBox1.Text, textBox2.Text);
            listBox1 .Items .Clear ();
           foreach (DictionaryEntry de in ht)
            {
                listBox1.Items.Add(de.Key+" "+de.Value );
 
            }
            MessageBox.Show("saved");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("not working now");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                ht.Remove("1");
               
            ht.Remove(textBox3.Text);
                ht.Remove(textBox4.Text);
                listBox1.Items.Remove(textBox3.Text + " " + textBox4.Text);
                MessageBox.Show("deleted");
            }
            catch
            {
            MessageBox.Show ("Not Deleted");
            }
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
          
           
            if(ht.Contains (textBox5 .Text))
            {     MessageBox .Show ("available");
            }
            else
            {
            MessageBox .Show ("not available");
            }
            }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void button7_Click(object sender, EventArgs e)
        {

            foreach (DictionaryEntry de in ht)
            {
                label3.Text = (de.Key + " " + de.Value);

            }
        }}}


hashtable assignment:



Hash table

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 hashtablewithfnlbutton
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Hashtable ht = new Hashtable();
        int i = 1,j;
       

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text==""||textBox2.Text== "") {

                MessageBox.Show("Enter name or Roll no.");
            }
            else {
               
                Class1 obj = new Class1();
                obj.Name = textBox1.Text;
                obj.Rollno = textBox2.Text;
                ht.Add(i, obj);
                i++;
          

            
                MessageBox.Show("saved");
            }



        }
     
 

        private void button5_Click(object sender, EventArgs e)
        {
            if (i == ht.Count)
            {

                MessageBox.Show("already on last");
            }
            else
            {
                i =ht.Count;
                Class1 obj = new Class1();
                obj = (Class1 )ht[i];
                textBox1.Text = obj.Name;
                textBox2.Text = obj.Rollno;
           
           
            }
        }

       

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (textBox4.Text == "")
            {
                MessageBox.Show("Enter input");
            }
            else
            {
                if(ht.Count ==0){
               
                 MessageBox.Show("no value stored");
                }else{j = int.Parse(textBox4.Text);
                      if (j == 0)
                {
                    MessageBox.Show("value starts from 1");
                }
                    else if (j <= ht.Count)
                {
                    Class1 obj = new Class1();
                    obj = (Class1)ht[j];
                    textBox1.Text = obj.Name;
                    textBox2.Text = obj.Rollno;
                }
              

                else
                {

                    MessageBox.Show("no valid input");
                }
            }}

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (i == 1)
            {
                MessageBox.Show("already on first record");
            }
            else
            {
                i = 1;
                Class1 obj = new Class1();
               obj =(Class1 ) ht[i];
                textBox1.Text = obj.Name;
                textBox2.Text = obj.Rollno;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (i == ht.Count)
            {
                MessageBox.Show("you already on last record");

            }
            else {
                i = i + 1;
                Class1 obj = new Class1();
                obj = (Class1)ht[i];
                textBox1.Text = obj.Name;
                textBox2.Text = obj.Rollno;

           
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (i == 1)
            {
                MessageBox.Show("already on first record");
            }
            else
            {
                i = i-1;
                Class1 obj = new Class1();
                obj = (Class1)ht[i];
                textBox1.Text = obj.Name;
                textBox2.Text = obj.Rollno;
            }
        }
    }
}
Classcoding:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace hashtablewithfnlbutton
{
    class Class1
    {
        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        string rollno;

        public string Rollno
        {
            get { return rollno; }
            set { rollno = value; }
        }
    }
}

Posted By:Tanuj Kumar 
On:Shareyourconscience



Read More
Posted on 9:03:00 pm
Categories: