int[] ia = { 1, 3, 2, 4, 8, 1, 5 };
int temp = 0;
for (int i = 0; i < ia.Length; i++) {
for (int j = 0; j < i; j++)
{
if (ia[i] < ia[j]) {
temp = ia[i];
ia[i] = ia[j];
ia[j] = temp;
}
}
}
int s = ia.Length;
//冒泡
int[] a = { 1, 3, 2, 4, 8, 1, 5 };
int t = 0;
for (int j = 0; j < a.Length-1; j++) //进行9轮排序 即n-1次
{
for (int i = 0; i < a.Length -1 - j; i++) //每轮进行n-1-j 次比较,最多n-1-j 次交换
if (a[i] > a[i + 1])
{
t = a[i];
a[i] = a[i + 1]; //小的沉底,大的上浮
a[i + 1] = t;
}
}
s = a.Length;
转载于:https://www.cnblogs.com/root_u/p/5132666.html