read pan 宋体 nbsp public () class 变量 sta
using System;
namespace sort
{
class MainClass
{
public static void Main (string[] args)
{
int [] sum=new int [5]{0,5,6,8,21};
for (int i = 0; i <sum.Length-1; i++)//总共要比较的趟数
{
for (int j =0; j < sum.Length-1-i; j++) //每趟要比较的次数
{
if(sum[j]<sum[j+1]) //判断两个数值的大小,若前面数比后面数值小,两个数交换位置
{
int team = sum[j];//定义交换变量
sum[j] = sum[j + 1];
sum[j+1]=team;
}
}
}
Console.Write("排序之后的数是:");//遍历数组
for (int i = 0; i < sum.Length; i++){
Console.WriteLine (sum[i]+""); }
Console.ReadKey ();
}
}
}
C#冒泡排序
来源: http://www.bubuko.com/infodetail-2353030.html