Quick Sort in-place implementation,quicksort_php Tutorial

Source: Internet
Author: User
Tags php online

Quick Sort In-place Implementation,quicksort


Running PHP http://www.compileonline.com/execute_php_online.php Online

1 
 Php2 functionSwap (&$a, &$b )3 {4     $c=$a;5     $a=$b;6     $b=$c;7 }8 9 /**Ten * Quick Sort One * Ascend A * In-place - */ - functionQuick_sort (&$a ) the { -     $s=Count($a);//size of a -     if($s< 2)return; -     $i= 0;//index of Pivot, for tracking pivot +     $pivot=$a[$i]; -     $l= 0;//swap Listener, if listens no swap, sort fini +  A //Swap those smaller than pivot to the left at      for($m= 0;$m<$s;$m++ ) -     { -         if($a[$m] <$a[$i] ) -         { -Swap$a[$m],$a[$i] ); -             $i=$m; in             $l++; -         } to     } +  -     //swap those larger than pivot to the right the      for($n= 0;$n<$i;$n++) *     { $         if($a[$n] >$a[$i] )Panax Notoginseng         { -Swap$a[$n],$a[$i] ); the             $i=$n; +             $l++; A         } the     } +  -     if($l= = 0)return; $     Else $l= 0; $Quick_sort ($a ); - } -  the $arr=Range(9, 0 ); -Quick_sort ($arr );Wuyi Echo implode( ', ',$arr ); the?>

http://www.bkjia.com/PHPjc/910351.html www.bkjia.com true http://www.bkjia.com/PHPjc/910351.html techarticle Quick Sort in-place implementation,quicksort online run phphttp://www.compileonline.com/execute_php_online.php 1? PHP 2 function swap ($a, $b) 3 {4 $c = $a; 5 $a = $b; 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.