Select Sort Selection Sort
The basic idea of sorting is to process the sequence of sorted records over n-1 times, and to process over 1st times, L [1 .. n] the smallest one exchanges location with L [1]. For 2nd times .. the smallest person in n] exchanges location with L [2 ,......, the I-th processing is to convert L [I .. the smallest person in n] exchanges location with L [I. In this way, after I times, the positions of the previous I records are arranged in ascending order.
Of course, in actual operations, you can also select the locations of the vertex and its first record from the record to be sorted and sort the records in the ascending order.
The algorithm is as follows:
/**
* Select sorting
* @ Paramsrc the array to be sorted
*/
Void doChooseSort (int [] src)
{
Int len = src. length;
Int temp;
For (int I = 0; I <len; I)
{
Temp = src [I];
Int j;
Int samllestLocation = I; // subscript of the minimum number
For (j = I 1; j <len; j)
{
If (src [j] <temp)
{
Temp = src [j]; // obtain the minimum value
SamllestLocation = j; // retrieve the subscript of the minimum value
}
}
Src [samllestLocation] = src [I];
Src [I] = temp;
PrintResult (I, src );
}
}