Home >> Snippet List >> Snippet

Name
Bubblesort routine
Description
Reasonably quick bubblesort routine
PHP Snippet
<? php
 
FUNCTION BubbleSort($sort_array,$reverse) 
{ 
FOR ($i = 0; $i < SIZEOF($sort_array); $i++){ 
FOR ($j = $i + 1; $j < SIZEOF($sort_array); $j++){ 
IF($reverse){ 
IF ($sort_array[$i] < $sort_array[$j]){ 
$tmp = $sort_array[$i]; 
$sort_array[$i] = $sort_array[$j]; 
$sort_array[$j] = $tmp; 
} 
}ELSE{ 
IF ($sort_array[$i] > $sort_array[$j]){ 
$tmp = $sort_array[$i]; 
$sort_array[$i] = $sort_array[$j]; 
$sort_array[$j] = $tmp; 
} 
} 
} 
} 
RETURN $sort_array; 
} 
?>