Skip to content

Instantly share code, notes, and snippets.

@barockok
Created October 1, 2011 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barockok/1256501 to your computer and use it in GitHub Desktop.
Save barockok/1256501 to your computer and use it in GitHub Desktop.
Sorting algorithm in PHP
function quickSort($array)
{
if (!$length = count($array)) {
return $array;
}
$k = $array[0];
$x = $y = array();
for ($i=1;$i<$length;$i++) {
if ($array[$i] <= $k) {
$x[] = $array[$i];
} else {
$y[] = $array[$i];
}
}
return array_merge(quickSort($x),array($k),quickSort($y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment