Skip to content

Instantly share code, notes, and snippets.

@SpekkoRice
Last active February 19, 2017 03:31
Show Gist options
  • Save SpekkoRice/fa5d61a6021ec729be680987ea0c30fa to your computer and use it in GitHub Desktop.
Save SpekkoRice/fa5d61a6021ec729be680987ea0c30fa to your computer and use it in GitHub Desktop.
function quicksort($seq) {
if(!count($seq)) return $seq;
$pivot= $seq[0];
$low = $high = array();
$length = count($seq);
for($i=1; $i < $length; $i++) {
// The index at which you would like to sort
$sortIndex = 0;
if($seq[$i][$sortIndex] <= $pivot[0]) {
$low [] = $seq[$i];
} else {
$high[] = $seq[$i];
}
}
return array_merge(quicksort($low), array($pivot), quicksort($high));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment