Quick sort PHP Implementation php Quick Sort Method Quick sort calculation of PHP quick sort

Source: Internet
Author: User
/** * Quick sort: Unstable, time complexity best O (nlogn) worst time O (n^2) * Quick Sort is an essential improvement on bubble sorting. Its basic idea is that after a scan, the length of the sequencing sequence can be significantly reduced. In a bubbling sort, a scan can only ensure that the number of maximum values is moved to the correct position, while the length of the sequence to be sorted may be reduced by only 1. Quick sort by a scan, you can make sure that the number of the left is smaller than it is, and the number on the right is larger than it. It then uses the same method to manipulate the left and right sides of the number until there is only one element to the left of the datum point. * @param Array $arr * @return Array */ functionfastsort(array $arr){if(Count ($arr) >1){$num=$arr[0];$arrSmall= [];$arrBig= [];foreach($arr as$item){if($item>$num){$arrBig[] =$item; }ElseIf($item<$num){$arrSmall[] =$item; }        }$arrSmall= Fastsort ($arrSmall);$arrBig= Fastsort ($arrBig);$arr= Array_merge ($arrSmall,[$num],$arrBig); }Else{return$arr; }return$arr;}

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the fast sort of PHP implementation, including the fast sorting, PHP content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.