stack:non generic collection
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.
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());
}
}
}
Comments
Post a Comment