-
-
Save parzibyte/4cab0ac91770de63e6b68e181bcd4e0f to your computer and use it in GitHub Desktop.
This file contains 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 | |
// https://parzibyte.me/blog | |
function burbuja(&$arreglo) | |
{ | |
$longitud = count($arreglo); | |
for ($i = 0; $i < $longitud; $i++) { | |
for ($j = 0; $j < $longitud - 1; $j++) { | |
if ($arreglo[$j] > $arreglo[$j + 1]) { | |
$temporal = $arreglo[$j]; | |
$arreglo[$j] = $arreglo[$j + 1]; | |
$arreglo[$j + 1] = $temporal; | |
} | |
} | |
} | |
} | |
$miArreglo = [5, 1, 80, 10, 7, 66, 100]; | |
echo "Antes de ordenar: "; | |
print_r($miArreglo); | |
# Lo ordenamos | |
burbuja($miArreglo); | |
echo "Después de ordenar: "; | |
print_r($miArreglo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment