using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace _1到100内随机十个数排序
{
class Program
{
static void Main(string[] args)
{
CreatRandArray();
Console.Write("随机数列:"+" ");
foreach (int item in ArrayRandom)
{
if (item/10<1)
{ Console.Write('0'+item.ToString() + " "); }
else
{ Console.Write(item + " "); }
}
Console.WriteLine(" ");
CreatSortArray();
Console.Write("排序数列:"+" ");
foreach (int item in ArraySort)
{
if (item / 10 < 1)
{ Console.Write('0' + item.ToString() + " "); }
else
{ Console.Write(item + " "); }
}
Console.ReadKey();
}
static int num;
static int max;
static int[] ArrayRandom = new int[10];
static int[] ArraySort = new int[10];
private static void CreatRandArray()
{
Random rd = new Random();
for (int i = 0; i <= 9; i++)
{
num = rd.Next(1, 100);
ArrayRandom[i] = num;
}
}
private static int FindMax(int[] array)
{
int max = array[0];
if (array.Length > 1)
{
for (int i = 1; i <= array.Length - 1; i++)
{
if (max < array[i])
{ max = array[i]; }
}
}
return max;
}
private static void CreatSortArray()
{
ArrayList list = new ArrayList(ArrayRandom);
max = FindMax(ArrayRandom);
for (int i = list.Count - 1; i >= 1 && i < list.Count; i--)
{
ArraySort[i] = max;
list.Remove(max);
int[] temp = (int[])list.ToArray(typeof(int));
max = FindMax(temp);
}
int[] last = (int[])list.ToArray(typeof(int));
ArraySort[0] = last[0];
}
}
}