外循环是进行的趟数n-1,内循环是每趟比较的次数 n-i
for (int j = 1; j <=arr.Length-1;j++ )
{
for (int k = 1; k <= arr.Length-j;k++ )
{
if (arr[k-1]<arr[k])
{
int z=arr[k];
arr[k] = arr[k-1];
arr[k-1] = z;
}
}
}
for (int i = 0; i < arr.Length;i++ )
{
Console.WriteLine(arr[i]);
}
时间: 2024-10-28 10:05:53