The object to be sorted is divided into two parts, one sorted, one unordered, one lowest from the unsorted part, and the last one in the sorted section above. For example:
Sort before: 70 80 31 37 10 1 48 60 33 80
[1] 80 31 37 10 70 48 60-33 80 Select a minimum value of 1
[1 10] 31 37 80 70 48 60 33 80 Select the minimum value 10
"[1 10 31] 37 80 70 48 60 33 80" Select the minimum value 31
[1 10 31 33] 80 70 48 60 37 80 ...
[1 10 31 33 37] 70 48 60 80 80 ...
[1 10 31 33 37 48] 70 60 80 80 ...
[1 10 31 33 37 48 60], 70 80 80 ...
[1 10 31 33 37 48 60 70] 80 80 ...
[1 10 31 33 37 48 60 70 80] 80 ...
C # instance:
private static void Selsort ()
{
int[] num = new int[] {m, 1, Panax Notoginseng, n
. int length = num. Length;
int min, temp;
Writenumline (num);
for (int i = 0; i < length; i++)
{
min = i;
for (int j = i; j < length; J +)
{
if (Num[min] > Num[j])
min = j;
}
if (i!= min)
{
temp = num[i];
Num[i] = num[min];
Num[min] = temp;
}
Writenumline (num);
}
Writenumline (num);
}
private static void Writenumline (int[] num)
{
foreach (int i in num)
{
Console.Write (i + "");
}
Console.WriteLine ();
}