日期:2014-05-20 浏览次数:21052 次
public void Print(params int[] data) { var b = data.ToList(); b.Sort(); foreach (var item in b) { Console.WriteLine(item); } }
------解决方案--------------------
int[] a = new int[5];
Random ran=new Random();
for (int i = 0; i < 5; i++)
{
int b = ran.Next(1, 100);
a[i] = b;
}
Array.Sort(a);
for (int j = 4; j >=0; j--)
{
Console.WriteLine(a[j]);
}
------解决方案--------------------
class Program { static void Main(string[] args) { int[] d = { 1, 3, 4, 2, 5 }; int[] r = sort(d); foreach (int i in r) { Console.WriteLine(i); } Console.ReadKey(); } static int[] sort(int[] d) { for (int i = 0; i < d.Length; i++) { for (int j = 0; j < d.Length - i - 1; j++) { int a = d[j]; int b = d[j + 1]; if (a > b) { d[j] = b; d[j + 1] = a; } } } return d; } }