Skip to content

Instantly share code, notes, and snippets.

@kentatogashi
Last active December 20, 2015 04:29
Show Gist options
  • Save kentatogashi/6070925 to your computer and use it in GitHub Desktop.
Save kentatogashi/6070925 to your computer and use it in GitHub Desktop.
Quick Sort
<?php
function quickSort(&$numArr,$left = 0,$right)
{
if($left >= $right) {
return;
}
swap($numArr,$left,ceil(($left+$right)/2));
$last = $left;
for($i = $left+1;$i<=$right;$i++) {
if($numArr[$i] < $numArr[$left]) {
swap($arrNum,++$last,$i);
}
}
swap($numArr,$left,$last);
quickSort($numArr,$left,$last - 1);
quickSort($numArr,$last + 1,$right);
}
function swap(&$numArr,$left,$right)
{
$tmp = $numArr[$right];
$numArr[$right] = $numArr[$left];
$numArr[$left] = $tmp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment