Simple selection and sorting(Simple
Selection sort). The simple selection and sorting operation is to select the records with the smallest keyword from n-I + 1 records through the comparison between n-I keywords, and exchanged with the I (1 <= I <= N) records. Time Complexity:O (N ^ 2).
// Simple selection and sorting
Void Cselectionsort: simpleselectionsort ( Void )
{
Const Int Count = 9 ;
Int L [count] = { 0 , 49 , 38 , 65 , 97 , 76 , 13 , 27 , 49 };
For ( Int I = 0 ; I < Count; ++ I)
{
Int J = Selectminkey (L, Count, I );
If (I ! = J)
{
Int Temp = L [I];
L [I] = L [J];
L [J] = Temp;
}
}
// Print the sorting result.
For ( Int I = 0 ; I < Count; ++ I)
{
Cout < L [I] < " \ T " ;
}
Cout < Endl;
}
// Simple selection and sorting of minimum values
Int Cselectionsort: selectminkey ( Int L [], Int Count, Int I)
{
Int Index = I;
For ( Int J = I + 1 ; J < Count; j ++ )
{
If (L [J] < L [Index])
Index = J;
}
Return Index;
}
Simple sorting is to select the element index with the minimum key value in the sequence to be sorted. Then it is exchanged with the first element of the sequence to be sorted. In Bubble sorting, two adjacent elements are exchanged in reverse order.