我正在使用排序方法和随机。 Button1
创建参数随机化数字、大小和最大数量限制。然后根据选择的线性方法,Button2
对这些数字进行排序,然后使用秒表计时花费了多长时间。我目前正在实施以 在文本文件中显示: sort method
、size
和。所以我已经完成了第一部分,当程序加载时,我已经提示用户创建一个文件来存储结果。 time_tosort
number of operations
我可以通过哪些方法将结果附加到 textFile 并对结果进行平均?我还需要在用户完成排序后添加一个按钮来关闭写入功能吗?
所需格式的示例 :sort method
、size
和time_tosort
number of operations
Linear 10000 .9 100,000,000
Linear 10000 .8 110,000,000
Linear 10000 .75 150,000,000
Linear 10000 .50 70,000,000
Linear 10000 .7375 107,500,000 ---- AVG
代码
namespace sortMachine
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Save()
{
var saveReport = new SaveFileDialog();
saveReport.Filter = "Text Files | *.txt";
var result = saveReport.ShowDialog();
if (result == DialogResult.Cancel || string.IsNullOrWhiteSpace(saveReport.FileName))
return;
using (var writer = new StreamWriter(saveReport.FileName))
{
writer.Write(textBox1.Text);
writer.Close();
}
}
private List<string> messages = new List<string>() { "Linear", "Bubble", "Index", "Other" };
private int clickCount = 0;
Stopwatch sw = new Stopwatch();
private void button1_Click(object sender, EventArgs e)
{
try
{
}
else if (textBox7.Text == "Bubble")
{
}
else if (textBox7.Text == "Index")
{
}
else if (textBox7.Text == "Other")
{
}
else if (textBox7.Text == "")
{
MessageBox.Show("Please input a sorting method");
}
}
private void Form1_Load(object sender, EventArgs e)
{
Save();
}
private void button3_Click(object sender, EventArgs e)
{
textBox7.Text = messages[clickCount];
clickCount++;
if (clickCount == messages.Count)
clickCount = 0;
}
}
}