Last active
July 15, 2016 19:34
-
-
Save Bolinha1/10787377 to your computer and use it in GitHub Desktop.
método de ordenação bolha (bubble sort) em 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
| <?php | |
| function bubbleSort($array) | |
| { | |
| for($i = 0; $i < count($array); $i++) | |
| { | |
| for($j = 0; $j < count($array) - 1; $j++) | |
| { | |
| if($array[$j] > $array[$j + 1]) | |
| { | |
| $aux = $array[$j]; | |
| $array[$j] = $array[$j + 1]; | |
| $array[$j + 1] = $aux; | |
| } | |
| } | |
| } | |
| } | |
| $arr = array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1); | |
| return var_dump(bubbleSort($arr)); // saída array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Falta um return não?