int[] list = new int[] { 100, 250, 110, 320, 120, 350, 550, 770, 660 };
for (int i = 0; i < list.Length; i++)
{
for (int j = i ; j < list.Length-i-1; j++)
{
if (list[j] > list[j+1])
{
int temp = list[j];
list[j] = list[j+1];
list[j+1] = temp;
}
}
}
for (int i = 0; i < list.Length; i++)
{
Console.WriteLine(list[i]+"");
}
经典的冒泡排序算法
最新推荐文章于 2024-11-09 20:38:27 发布