Last active
February 19, 2017 03:31
-
-
Save SpekkoRice/fa5d61a6021ec729be680987ea0c30fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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