Created
May 19, 2016 23:52
-
-
Save konstantinos-tsatsarounos/58e4d9188ddb7568cc952988ad7d339c to your computer and use it in GitHub Desktop.
Insertion sort algorithm for php
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 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