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