Straight selection sort)
Basic Idea of directly selecting sorting
The Direct selection and sorting of files with N records can be directly selected and sorted through n-1 rows to get the ordered results:
① Initial status: the disordered area is R [1. N], and the ordered area is empty.
② Sorting by 1st bits
In the unordered zone R [1 .. n] selects the record R [k] with the minimum keyword, swaps it with the 1st records R [1] In the unordered area, so that R [1 .. 1] and R [2 .. n] into a new ordered area with one more record count and a new unordered area with one fewer record count.
......
③ Sort by I
At the beginning of the I-th sorting, the current ordered and disordered areas are R [1 .. I-1] and R [I. N] (1 ≤ I ≤ N-1), respectively ). This sort field selects the record R [k] with the smallest keyword from the current unordered area and exchanges it with the 1st records R [I] In the unordered area, so that R [1 .. i] and R [I + 1 .. n] into a new ordered area with one more record count and a new unordered area with one fewer record count.
In this way, the direct sorting of files with N records can be directly selected through n-1 to obtain the ordered results.
Using system;
Using system. Collections. Generic;
Using system. text;
Namespace exselectionsorter
{
Class selectionsorter
{
Private int min;
Public void sort (INT [] ARR)
{
For (INT I = 0; I <arr. Length-1; ++ I)
{
Min = I;
For (Int J = I + 1; j <arr. length; ++ J)
{
If (ARR [J] <arr [Min])
Min = J;
}
Int T = arr [Min];
Arr [Min] = arr [I];
Arr [I] = T;
}
}
Static void main (string [] ARGs)
{
Int [] array = new int [] {1, 5, 3, 6, 10, 55, 9, 2, 87, 12, 34, 75, 33, 47 };
Selectionsorter S = new selectionsorter ();
S. Sort (array );
Foreach (INT m in array)
Console. writeline ("{0}", M );
}
}
}