我正在尝试使用冒泡排序,在 c# 中从最小到最大排序数字,到目前为止我有什么问题?
private void Order_Click(object sender, EventArgs e) {
value1 = Convert.ToInt32(textBox1.Text);
value2 = Convert.ToInt32(textBox2.Text);
value3 = Convert.ToInt32(textBox3.Text);
value4 = Convert.ToInt32(textBox4.Text);
value5 = Convert.ToInt32(textBox5.Text);
int[] myarray = { value1, value2, value3, value4, value5 };
int n = 0;
bool swapped = true;
int j = 0;
int tmp;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < n - j; i++)
{
if (myarray[i] > myarray[i + 1]) {
tmp = myarray[i];
myarray[i] = myarray[i + 1];
myarray[i + 1] = tmp;
swapped = true;
order1.Text = Convert.ToString(myarray[0] + "," +
myarray[1] + "," +
myarray[2] + "," +
myarray[3] + "," +
myarray[4]);
}
}
}
}