Skip to content

Instantly share code, notes, and snippets.

@SirMax28
Created February 7, 2025 04:06
Show Gist options
  • Save SirMax28/e894ae04176270a597cf0b1809608a4d to your computer and use it in GitHub Desktop.
Save SirMax28/e894ae04176270a597cf0b1809608a4d to your computer and use it in GitHub Desktop.
Algoritmo de Ordenación Burbuja en Python
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