int[]a=new int[]{1,2,5,3,4,8,6,7,9};
int temp=0;
for(int i=0;i<a.Length;i++)
{
for(int j=0;j<a.Length-i-1;j++)
{
if(a[j]>a[j+1]
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
foreach(var item in a)
{
Console.WriteLine(item+" ")
}
Console.ReadKey();
冒泡排序
最新推荐文章于 2022-04-29 23:24:15 发布