📄 form1.cs
字号:
a.current = b;
x = x - width - 10;
if (b.next != null)
b = b.next;
else
break;
}
}
y += height + 10;
}
Draw();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("请输入初始化单链表长度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
}
else
{
int length = Convert.ToInt16(textBox1.Text);
if (length > 99)
{
MessageBox.Show(" 初始化单链表长度应在0~99之间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
return;
}
if (radioButton1.Checked)
{
SListnode b = new SListnode(1);
a.head.next = b;
a.current = b;
for (int i = 2; i < length + 1; i++)
{
b = new SListnode(i);
a.current.next = b;
a.current = b;
}
Draw();
}
if (radioButton2.Checked)
{
SListnode b = new SListnode(length);
a.head.next = b;
a.current = b;
for (int i = length-1; i >0; i--)
{
b = new SListnode(i);
a.current.next = b;
a.current = b;
}
a.current = a.head.next;
Draw();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("请先进行初始化", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
}
else
{
int length = Convert.ToInt16(textBox1.Text);
if (length > 99)
{
MessageBox.Show(" 初始化单链表长度应在0~99之间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
return;
}
if (radioButton2.Checked)
{
SListnode b = new SListnode(1);
a.head.next = b;
a.current = b;
for (int i = 2; i < length + 1; i++)
{
b = new SListnode(i);
a.current.next = b;
a.current = b;
}
Draw();
}
if (radioButton1 .Checked)
{
SListnode b = new SListnode(length);
a.head.next = b;
a.current = b;
for (int i = length - 1; i > 0; i--)
{
b = new SListnode(i);
a.current.next = b;
a.current = b;
}
a.current = a.head.next;
Draw();
}
}
}
private void button5_Click(object sender, EventArgs e)
{
a.MakeEmpty();
Draw();
}
private void button3_Click(object sender, EventArgs e)
{
a.current = a.head;
Draw();
}
private void button4_Click(object sender, EventArgs e)
{
if (a.current.next != null)
{
a.current = a.current.next;
Draw();
}
else
{
MessageBox.Show("已经到达单链表尾端", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
}
}
private void button9_Click(object sender, EventArgs e)
{
if (a.current != null )
{
textBox3.Text = a.current.ToString();
textBox4.Text = Convert.ToString(a.current.data);
if(a.current.next!=null)
textBox5.Text = a.current.next.data.ToString();
}
else
{
MessageBox.Show("请初始化单链表", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
}
}
private void button7_Click_1(object sender, EventArgs e)
{
if (a.Length() == 99)
{
MessageBox.Show("单链表长度应在0~99之间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
bool before;
if (textBox2.Text == "")
{
MessageBox.Show("请在文本框中输入插入值", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
}
else
{
int newdata = Convert.ToInt16(textBox2.Text);
if (radioButton3.Checked)
{
before = true;
a.insert(newdata, before);
Draw();
}
if (radioButton4.Checked)
{
before = false;
a.insert(newdata , before);
Draw();
}
}
}
private void button6_Click(object sender, EventArgs e)
{
if (textBox2.Text == "")
{
MessageBox.Show("请输入修改值", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
}
else
{
if (a.current ==null )
{
MessageBox.Show("请初始化单链表", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
}
else
{
int newdata = Convert.ToInt16(textBox2.Text);
a.modifydata(newdata);
Draw();
}
}
}
private void button8_Click_1(object sender, EventArgs e)
{
if (a.current == a.head)
{
MessageBox.Show("删除错误,不能删除头结点", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
Draw();
}
else
{
a.delete();
Draw();
}
}
private void button10_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -