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++;
}
}
}选择排序
最新推荐文章于 2024-09-28 22:14:04 发布
本文介绍了一个简单的选择排序算法的实现方法,并通过一个C#示例程序进行了展示。该程序首先从用户输入获取一个整数数组,然后使用选择排序算法对其进行排序,并最终输出排序后的数组。
18万+

被折叠的 条评论
为什么被折叠?



