Introduction: This is a Data Structure &Algorithm(PhP description) insert a detailed page of the sort straight binary sort in a half-fold manner, introducing PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 341542 'rolling = 'no'>
1 <? PHP
2 /**
3 * Half-fold insert sorting straight binary sort
4 *
5 * principle: When directly inserted sorting to a trip, for R [I], the front side of the I-1 records have been sorted by keywords. In this case, you do not need to insert the sorting method directly. Instead, you can find the position where R [I] should be inserted and insert it.
6 */
7 function sort_binary_insertion ($ List)
8 {
9 $ Len = count ($ list );
10 if (empty ($ Len) return $ list;
11
12 For ($ I = 1; $ I <$ Len; $ I ++)
13 {
14 $ temp = $ list [$ I];
15 $ low = 0;
16 $ high = $ I-1;
17
18 while ($ low <= $ high)
19 {
20 $ mid = intval ($ low + $ high)/2 );
21
22 // if ($ temp> $ list [$ mid]) // from large to small
23 if ($ temp <$ list [$ mid]) // from small to large
24 {
25 $ high = $ mid-1;
26} else {
27 $ low = $ Mid + 1;
28}
29}
30 For ($ J = $ I-1; $ J >=$ mid; $ j --)
31 {
32 $ list [$ J + 1] = $ list [$ J];
33 echo implode (",", $ list), "# mid =", $ mid, "<br/> ";
34}
35 $ list [$ low] = $ temp;
36 echo implode (",", $ list), "<br/> ";
37 echo "-------------------------------- <br/> ";
38}
39
40 return $ list;
41}
42
43
44 $ list = array );
45 $ list = sort_binary_insertion ($ list );
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/341542.html pageno: 6.