当排序的数少的时候,比如说3个,可以用这种排序法
int a, b, c, t=0;
if (a < b) //本条件语句实现a>=b
{ t = a; a = b; b = t; }
if (a < c) //本条件语句实现a>=c
{ t = a; a = c; c = t; }
if (b < c) //本条件语句实现b>=c
{ t = b; b = c; c = t; }
Console.WriteLine("排序结果为: {0},{1},{2}",a,b,c);
还有就是可以用数组冒泡法排序。比如十个数排序
int[] a = new int[11];
int i, j, t, min, temp;
Console.WriteLine("input 10 numbers :\n");
for (i = 1; i < 11; i++)
a[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("当前数据个数已经全部输入完毕!");
Console.WriteLine();
for(j=1;j<=9;j++)
for(i=1;i<=10-j;i++)
if(a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
//输出排序结果
for (i = 1; i < 11; i++)
Console.WriteLine("{0}", a[i]);
Console.ReadLine();