function bubbingSort(array $array)
{
for($i=0, $len=count($array)-1; $i {
for($j=$len; $j>$i; --$j)
{
if($array[$j] {
$temp = $array[$j];
$array[$j] = $array[$j-1];
$array[$j-1] = $temp;
}
}
}
return $array;
}
print '
';<br> print_r(bubbingSort(array(1,4,22,5,7,6,9)));<br> print '
';
function quickSort(array $array)
{
$len = count($array);
if($len {
return $array;
}
$key = $array[0];
$left = array();
$right = array();
for($i=1; $i {
if($array[$i] {
$left[] = $array[$i];
}
else
{
$right[] = $array[$i];
}
}
$left = quickSort($left);
$right = quickSort($right);
return array_merge($left, array($key), $right);
}
print '
';<br> print_r(quickSort(array(1,4,22,5,7,6,9)));<br> print '
';