int[] scores = new int[] { 3,11,15, 5, 6, 7, 9 };
for (int i = 0; i < scores.Length-1; i++)
{
for (int j = 0; j < scores.Length-1-i; j++)
{
if (scores[j]>scores[j+1])
{
int item = scores[j];//存储最大值
scores[j] = scores[j+1];//最前面的是最小值
scores[j + 1] = item;//放在数组的最后
}
}
}
for (int i = 0; i < scores.Length; i++)
{
Console.WriteLine(scores[i]);
}
Console.ReadLine();
输出结果是:3,5,6,7,9,11,15
//每循环一次都有一个最大值放在数组的最后