Quick Search:
 
 PHP Code: Bubblesort routine Jump to:  
Category: >> PHP Code >> Bubblesort routine  

<< lastnext >>

Snippet Name: Bubblesort routine

Description: Reasonably quick bubblesort routine.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

<? 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; 
} 
?> 
 
//Use like this :
//$array = array{10,65,32,41,1,99}; 
//$sorted = BubbleSort($array,0);


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org