Created
February 7, 2025 04:06
-
-
Save SirMax28/e894ae04176270a597cf0b1809608a4d to your computer and use it in GitHub Desktop.
Algoritmo de Ordenación Burbuja en Python
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
def bubble_sort(arr): | |
n = len(arr) | |
for i in range(n): | |
# Últimos i elementos ya están ordenados | |
for j in range(0, n-i-1): | |
# Intercambiar si el elemento encontrado es mayor que el siguiente | |
if arr[j] > arr[j+1]: | |
arr[j], arr[j+1] = arr[j+1], arr[j] | |
# Ejemplo de uso | |
arr = [64, 34, 25, 12, 22, 11, 90] | |
bubble_sort(arr) | |
print("Arreglo ordenado:", arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment