asp.net下实现输入数字的冒泡排序
程序员文章站
2024-03-08 09:23:04
复制代码 代码如下: protected void btnsort_click(object sender, eventargs e) { string array1 =...
复制代码 代码如下:
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]);
}
}