主题:刚学C#.汉诺塔经典递归算法...有需要的来看看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication5
{
public partial class Form1 : Form
{
string s;
public Form1()
{
InitializeComponent();
}
public void f(int n,string a,string b,string c)
{
if (n>1)
{
f(n-1,a,c,b);
s += a + "--->" + c + "\n";
f(n-1,b,a,c);
}
else if(n==1)
s += a + "--->" + c + "\n";
else
MessageBox.Show("笨蛋!"+"\t"+"n的值不能小于1","出错信息",MessageBoxButtons.RetryCancel,MessageBoxIcon.Information);
}
private void button1_Click(object sender, EventArgs e)
{
int n;
n = Int32.Parse(textBox1.Text);
f(n,"a","b","c");
label2.Text = s;
}
}
}
小弟不才,想借地方顺便问一下,,,label标签属性中没能找到添加竖直方向的滚动条那个选项,能否在代码中定义,如果能,可以麻烦大虾告诉下么.
谢谢了|!!!!!!!!!!!!!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication5
{
public partial class Form1 : Form
{
string s;
public Form1()
{
InitializeComponent();
}
public void f(int n,string a,string b,string c)
{
if (n>1)
{
f(n-1,a,c,b);
s += a + "--->" + c + "\n";
f(n-1,b,a,c);
}
else if(n==1)
s += a + "--->" + c + "\n";
else
MessageBox.Show("笨蛋!"+"\t"+"n的值不能小于1","出错信息",MessageBoxButtons.RetryCancel,MessageBoxIcon.Information);
}
private void button1_Click(object sender, EventArgs e)
{
int n;
n = Int32.Parse(textBox1.Text);
f(n,"a","b","c");
label2.Text = s;
}
}
}
小弟不才,想借地方顺便问一下,,,label标签属性中没能找到添加竖直方向的滚动条那个选项,能否在代码中定义,如果能,可以麻烦大虾告诉下么.
谢谢了|!!!!!!!!!!!!!