sorting

John

New Member
1.
<?
2.

3.
function bubblesort($sort_array,$reverse)
4.
{
5.
for ($i = 0; $i < sizeof($sort_array); $i++){
6.
for ($j = $i + 1; $j < sizeof($sort_array); $j++){
7.
if($reverse){
8.
if ($sort_array[$i] < $sort_array[$j]){
9.
$tmp = $sort_array[$i];
10.
$sort_array[$i] = $sort_array[$j];
11.
$sort_array[$j] = $tmp;
12.
}
13.
}else{
14.
if ($sort_array[$i] > $sort_array[$j]){
15.
$tmp = $sort_array[$i];
16.
$sort_array[$i] = $sort_array[$j];
17.
$sort_array[$j] = $tmp;
18.
}
19.
}
20.
}
21.
}
22.
return $sort_array;
23.
}
24.

25.
$array = array{10,65,32,41,1,99};
26.
$sorted = bubblesort($array,0);
27.

28.
?>
 

Sara

New Member
Sorry

1.
<?
2.

3.
function bubblesort($sort_array,$reverse)
4.
{
5.
for ($i = 0; $i < sizeof($sort_array); $i++){
6.
for ($j = $i + 1; $j < sizeof($sort_array); $j++){
7.
if($reverse){
8.
if ($sort_array[$i] < $sort_array[$j]){
9.
$tmp = $sort_array[$i];
10.
$sort_array[$i] = $sort_array[$j];
11.
$sort_array[$j] = $tmp;
12.
}
13.
}else{
14.
if ($sort_array[$i] > $sort_array[$j]){
15.
$tmp = $sort_array[$i];
16.
$sort_array[$i] = $sort_array[$j];
17.
$sort_array[$j] = $tmp;
18.
}
19.
}
20.
}
21.
}
22.
return $sort_array;
23.
}
24.

25.
$array = array{10,65,32,41,1,99};
26.
$sorted = bubblesort($array,0);
27.

28.
?>


Hello,
When i use your given URL it seems some error and it's not sorted array properly.Please check it once so i can use it.

Thanks
 
Top