Important alert: (current site time 7/15/2013 10:56:02 AM EDT)
 

VB icon

Quicksort

Email
Submitted on: 10/29/2000 5:13:54 PM
By: PHP Code Exchange  
Level: Intermediate
User Rating: Unrated
Compatibility: PHP 3.0, PHP 4.0
Views: 18729
 
     quick sort for associative arrays by David Sklar
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Quicksort
// Description:quick sort for associative arrays by David Sklar
// By: PHP Code Exchange
//**************************************

<?
function qsort($a,$f) {
qsort_do(&$a,0,Count($a)-1,$f);
}
function qsort_do($a,$l,$r,$f) {
if ($l < $r) {
qsort_partition(&$a,$l,$r,&$lp,&$rp,$f);
qsort_do(&$a,$l,$lp,$f);
qsort_do(&$a,$rp,$r,$f);
}
}
function qsort_partition($a,$l,$r,$lp,$rp,$f) {
$i = $l+1;
$j = $l+1;
while ($j <= $r) {
if ($f($a[$j],$a[$l])) {
$tmp = $a[$j];
$a[$j] = $a[$i];
$a[$i] = $tmp;
$i++;
}
$j++;
}
$x = $a[$l];
$a[$l] = $a[$i-1];
$a[$i-1] = $x;
$lp = $i - 2;
$rp = $i;
}
?>


Other 192 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.