Introduction: This is a Data Structure &Algorithm(PhP description) The detailed page of Simple selection sort for simple selection and sorting describes PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 343577 'rolling = 'no'>
1 <? PHP
2 /**
3 * simple selection and sorting simple selection sort
4 *
5 * principle: select each number in the array at a time, write down the current position, and assume that it is the minimum number min = I in the number following the current position, scanning from the next number of this number until the last number, and recording the min position of the minimum number. If Min is not equal to I after scanning, it is assumed that it is incorrect, the number of Min and I positions is switched.
6 */
7 function sort_simple_selection ($ List)
8 {
9 $ Len = count ($ list );
10 if (empty ($ Len) return $ list;
11
12 For ($ I = 0; $ I <$ Len; $ I ++)
13 {
14 $ min = $ I;
15 For ($ J = $ I + 1; $ j <$ Len; $ J ++)
16 {
17 // if ($ list [$ J]> $ list [$ Min]) // from large to small
18 if ($ list [$ J] <$ list [$ Min]) // from small to large
19 {
20 $ min = $ J;
21
22}
23 echo implode (',', $ list ). "# Pos = ". ($ min + 1 ). "min = ". $ list [$ Min]. "<br/> ";
24}
25 if ($ Min! = $ I)
26 {
27 $ temp = $ list [$ I];
28 $ list [$ I] = $ list [$ Min];
29 $ list [$ Min] = $ temp;
30}
31 echo "------------------------- <br/> ";
32}
33}
34
35 $ list = array );
36 $ list = sort_simple_selection ($ list );
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/343577.html pageno: 5.