冒泡
1 for (i = 0; i < scores.Length -1 ; i++)
2 {
3 for (j = 0; j < scores.Length -1 - i ; j++)
4 {
5 if (scores[j] > scores[j + 1])
6 {
7 // 交换元素
8 temp = scores[j];
9 scores[j] = scores[j + 1];
10 scores[j + 1] = temp;
11 }
12 }13 }
1 3 5 7 ... 2 * i - 1 2 4 6 8 ... 2 * i
2 {
3 for (j = 0; j < scores.Length -1 - i ; j++)
4 {
5 if (scores[j] > scores[j + 1])
6 {
7 // 交换元素
8 temp = scores[j];
9 scores[j] = scores[j + 1];
10 scores[j + 1] = temp;
11 }
12 }13 }
1 3 5 7 ... 2 * i - 1 2 4 6 8 ... 2 * i