Skip to content

Instantly share code, notes, and snippets.

@daqing
Created June 7, 2009 11:02
Show Gist options
  • Select an option

  • Save daqing/125282 to your computer and use it in GitHub Desktop.

Select an option

Save daqing/125282 to your computer and use it in GitHub Desktop.
<?php
function insertion_sort($seq)
{
$size = count($seq);
for ($i = 1; $i < $size; $i ++) {
$key = $seq[$i];
$left = $i - 1;
while ($left >= 0 && $seq[$left] > $key) {
$seq[$left + 1] = $seq[$left];
$seq[$left] = $key;
$left --;
}
}
return $seq;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment