C#栈和队列的应用实例源码
private void button1_Click(object sender, EventArgs e)
{
if (textBox3.Text.Length > 0)
{
if (IsIDnum(textBox3.Text.Trim()))
{
int i = Convert.ToInt32(textBox3.Text.Trim());
b.Push(i);
str = str + textBox3.Text.Trim() + ",";
label4.Text = str;
textBox3.Text = "";
}
else
{
textBox3.Text = "必须为数字";
}
}
else
{
textBox3.Text = "不能为空";
}
}
private void button3_Click(object sender, EventArgs e)
{
if (b.Count == 0)
{
textBox4.Text = "栈为空";
label4.Text ="";
}
else
{
textBox4.Text = b.Pop().ToString();
int n = str.LastIndexOf(",");
str = str.Substring(0, n);
int m = str.LastIndexOf(",");
str = str.Substring(0, m+1);
label4.Text = str;
}
}
2023-03-20 15:30:26
40KB
栈和队列
1