Select the sorting method: in the sorting array, select the minimum (or maximum) number to exchange with the number of 1st positions, and then find the minimum (or maximum) number among the remaining values) and so on until the nth element (second to last) and NTH element (last number) are compared.
Implementation ideas:
1. Find the minimum number (maximum number) each time );
2. Find the minimum number and the I-th array for the I-th;
3. Repeat (1) (2) until the sorting is successful;
|
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
6 |
10 |
4 |
90 |
52 |
77 |
8 |
3 |
0 |
3 |
10 |
4 |
90 |
52 |
77 |
8 |
6 |
1 |
3 |
4 |
10 |
90 |
52 |
77 |
8 |
6 |
2 |
3 |
4 |
6 |
90 |
52 |
77 |
8 |
10 |
3 |
3 |
4 |
6 |
8 |
52 |
77 |
90 |
10 |
4 |
3 |
4 |
6 |
8 |
10 |
77 |
90 |
52 |
5 |
3 |
4 |
6 |
8 |
10 |
52 |
90 |
77 |
6 |
3 |
4 |
6 |
8 |
10 |
52 |
77 |
90 |
Code implementation:
/*************************************** **************************************** * ******* Description: * input ARGs: * output ARGs: * return value: **************************************** **************************************** * ***/INT select_sort (INT array [], int N) {int I, j; int temp, little; for (I = 0; I <n-1; I ++) {/* Find the min one */little = I; for (j = I + 1; j <n; j ++) {If (array [little]> array [J]) // small to large little = J ;}
/* Exchange the postion if not the min one */If (little! = I) {temp = array [little]; array [little] = array [I]; array [I] = temp ;}} return 0 ;} /* ----- end of select_sort ()-----*/
Reference: http://blog.csdn.net/caryaliu/article/details/7438592
Sorting Algorithm: Select sorting method