using System;
using System.Collections.Generic;
using System.Text;
namespace 数组排序_升序排列_
{
class Program
{
static void Main(string[] args)
{
int[] myArray = new int[10] { 10, 54, 34, 45, 4, 8, 38, 9, 7, 11 };
Console.WriteLine("原始数组为: ");
foreach (int number in myArray)
{
Console.Write(number + " ");
}
Console.WriteLine();
int i, j, t, min;
for (i = 0; i < 10; i++)
{
min = i;
for (j = i + 1; j < 10; j++)
{
if (myArray[j] < myArray[min])
{
min = j;
}
}
if (min != i)
{
t = myArray[i];
myArray[i] = myArray[min];
myArray[min] = t;
}
Console.WriteLine("排序后数组为: ");
foreach (int number in myArray)
{
Console.Write(number +" ");
}
Console.ReadLine();
}
}
}
}
代码就这样,为什么没排好序?只有两个数字位置变化了。