PHP
<?php
function quickSort(&$array, $sort_type)
{
if (count($array) <= 1) {
return $array;
}
$middle = $array[0];
$left = array();
$right = array();
for ($i = 1; $i < count($array); $i++) {
if ('DESC' == strtoupper($sort_type)) {
$flag = $array[$i] >= $middle;
} else {
$flag = $array[$i] <= $middle;
}
if ($flag) {
$left[] = $array[$i];
} else {
$right[] = $array[$i];
}
}
$left = quickSort($left, $sort_type);
$right = quickSort($right, $sort_type);
return array_merge($left, array($middle), $right);
}
$array = array(1,4,2,6,3,4,9,0,2,1);
$array = quickSort($array, "DESC");
echo var_dump($array);