asp.net下实现输入数字的冒泡排序

时间:2021-05-28

复制代码 代码如下:
protected void btnSort_Click(object sender, EventArgs e)
{
string array1 = txtSort.Text.Trim();
string[] array21=array1.Split(',');
int dxiao = array21.Length;
int[] array = new int[dxiao];
int temp=0;
for (int i = 0; i < array.Length; i++)
{
array[i] = Convert.ToInt32(array21[i]);
}
for (int i = 0; i < array.Length - 1; i++)
{
for (int j = i + 1; j < array.Length; j++)
{
if (array[j] < array[i])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
for (int i = 0; i < dxiao; i++)
{
lbsort.Text = lbsort.Text + " " + Convert.ToString(array[i]);
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章