class Program
{
static void Main(string[] args)
{
int[] test = new int[5];
for (int i = 0; i < 5; i++)
{
test[i] = Convert.ToInt32(Console.ReadLine());
}
selectsort(test, 5);
foreach (int a in test)
{
Console.Write(a + " ");
}
Console.WriteLine();
}
static public void selectsort(int[] array, int length)
{
int i=0,j,min,temp_array,temp;
while (i < length - 1)
{
min = array[i];
temp = i;
for (j = i + 1; j < length; j++)
{
if (array[j] < min)
{
min=array[j];
temp = j;
}
}
temp_array=array[i];
array[i] = array[temp];
array[temp] = temp_array;
i++;
}
}
}
选择排序
最新推荐文章于 2014-11-27 19:17:19 发布