Skip to content

Instantly share code, notes, and snippets.

@konstantinos-tsatsarounos
Created May 19, 2016 23:52
Show Gist options
  • Select an option

  • Save konstantinos-tsatsarounos/58e4d9188ddb7568cc952988ad7d339c to your computer and use it in GitHub Desktop.

Select an option

Save konstantinos-tsatsarounos/58e4d9188ddb7568cc952988ad7d339c to your computer and use it in GitHub Desktop.
Insertion sort algorithm for php
function shortNumbers(array $numbers){
$counter = 1;
for(;$counter < count($numbers); $counter++){
$x = $numbers[$counter];
$j = $counter - 1;
while ( $j>=0 && $numbers[$j] > $x ){
$numbers[$j + 1] = $numbers[$j];
$j--;
}
$numbers[$j + 1] = $x;
}
return $numbers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment