asp.net下实现输入数字的冒泡排序
(编辑:jimmy 日期: 2024/11/3 浏览:3 次 )
复制代码 代码如下:
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]);
}
}
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]);
}
}
下一篇:asp.net页面master页面与ascx用户控件传值的问题