# Include <iostream>
/* Select sorting
Basic Idea: Find the smallest one from the back and put it to the last one sorted in the front.
Features: time complexity O (N ^ 2)
*/
Void selectsort (INT array [], int N ){
Int I, J;
Int temp = 0, flag = 0;
For (I = 0; I <n-1; I ++ ){
Temp = array [I];
Flag = I;
For (j = I + 1; j <n; j ++ ){
If (array [J] <temp) {// retrieve from I + 1 ~ The minimum one of N-1 is put into temp.
Temp = array [J];
Flag = J;
}
}
// Avoid assigning values. In extreme cases, values 1, 2, 3, 4, and 5 are ordered.
If (flag! = I ){
Array [flag] = array [I]; // place the value of a [I] to flag
Array [I] = temp; // the value of a [I] is equal to I + 1 ~ N-1)
}
}
}
Int main (INT argc, const char * argv [])
{
Int I = 0;
Int A [] = };
Int Len = sizeof (a)/sizeof (A [0]);
// Select sorting
Selectsort (A, Len );
For (I = 0; I <Len; I ++ ){
Printf ("% d", a [I]);
}
Printf ("\ n ");
Return0;
}
Deep introduction to sorting algorithms-select sorting