// int[] list = { 0, 2, 6, 3, 5, 1, 4, 9, 7, 8 };
int[] list = new int[10];
for (int i = 0; i < 10; i++)
{
list[i] = Convert.ToInt32( Console.ReadLine());
}
Console.WriteLine("排序前:");
for (int i = 0; i < list.Length; i++)
Console.WriteLine(list[i]);
Console.WriteLine();
int tmp = 0;
bool isOK = false;
while (!isOK)
{
isOK = true;
for (int i = 0; i <= list.Length - 2; i++)
{
//Console.WriteLine(i);
if (list[i ] > list[i+1 ])
{
tmp = list[i];
list[i] = list[i + 1];
list[i + 1] = tmp;
isOK = false;
}
}
}
Console.WriteLine("排序后:");
for (int i = 0; i < list.Length; i++)
Console.WriteLine(list[i]);
Console.WriteLine();
C#的对数组排序
最新推荐文章于 2022-10-24 09:31:52 发布