//冒泡排序
int []scores = {10,20,144,24,574,2,56,66,59,45,4,5,6,8,4,55,41,40};
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 tmp=scores[j];
scores[j] = scores[j + 1];
scores[j + 1] = tmp;
}
}
}
for (int i = 0; i < scores.Length;i++ )
{
Console.WriteLine(scores[i]);
}
Console.ReadKey();
数据结构——简单的冒泡排序
最新推荐文章于 2020-08-03 08:58:26 发布