Skip to content

Instantly share code, notes, and snippets.

@kentatogashi
Created July 26, 2013 14:35
Show Gist options
  • Save kentatogashi/6089337 to your computer and use it in GitHub Desktop.
Save kentatogashi/6089337 to your computer and use it in GitHub Desktop.
<?php
function qs($seq){
if(count($seq) == false)return $seq;
$pivot = $seq[0];
$low = $high = array();
$length = count($seq);
for($i = 1;$i < $length;$i++){
if($seq[$i] < $pivot){
$low[] = $seq[$i];
} else {
$high[] = $seq[$i];
}
}
return array_merge(qs($low),array($pivot),qs($high));
}
//ソート対象の配列
$numArr = array(26,15,34,21,92,32,1);
echo "ソート前";
echo "<pre>";
print_r($numArr);
echo "</pre>";
echo "ソート後";
echo "<pre>";
$final = qs($numArr);
print_r($final);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment