使用C#完成冒泡排序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 冒泡排序
{
class Program
{
static void Main(string[] args)
{
int[] sores = { 18, 19, 20, 45, 62, 32, 89, 75, 41, 32, 69 };

for (int i = 0; i < sores.Length-1; i++)
for (int j = 0; j<sores.Length-1; j++)
{
int team;
if (sores[j] < sores[j+1])
{
team = sores[j];
sores[j] = sores[j +1];
sores[j +1] = team;


}
}
Console.WriteLine("按顺序从小到大排列后的数组是");
for(int i=0;i<sores.Length;i++)
Console.Write(sores[i]+" ");
Console.ReadKey();
}
}
}

猜你喜欢

转载自www.cnblogs.com/qmk-716/p/9900118.html
今日推荐