今天工作不是太忙,无意间翻博客看到冒泡排序的算法,热血沸腾也想写一个出来。好久没写过了。
代码贴出来:
Response.Write("原始数据为:" + words+"<br/>");
int[] array = new int[] { 10, 56, 98, 23, 77, 68, 5 };
for (int i = 0; i < array.Length; i++)
{
for (int j = i + 1; j < array.Length; j++)
{
if (array[i] < array[j])
{
int n = array[i];
array[i] = array[j];
array[j] = n;
}
}
}
string result = "";
for (int i = 0; i < array.Length; i++)
result += array[i] + ",";
Response.Write("修改数据为:" + result);
原始数据为:10,56,98,23,77,68,5
修改数据为:98,77,68,56,23,10,5,