Data Structure & algorithm (PhP description) Semi-fold insertion sorting straight binary sort

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.