您的位置:首页 > 编程语言 > ASP

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

2010-03-02 00:00 447 查看
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]); 
} 
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: