1
def bubble_sort(lista):
elementos = len(lista)-1
ordenado = False
while not ordenado:
ordenado = True
for i in range(elementos):
if lista[i] > lista[i+1]:
lista[i], lista[i+1] = lista[i+1],lista[i]
ordenado = False
print(lista)
return lista
Print like this bubble_sort([5, 1, 4, 2])
[1, 5, 4, 2]
[1, 4, 5, 2]
[1, 4, 2, 5]
[1, 2, 4, 5]
should return [1, 2, 4, 5]
He is printing bubble_sort([5, 1, 4, 2])
[1, 4, 2, 5]
[1, 2, 4, 5]
[1, 2, 4, 5]
[1, 2, 4, 5]
Thank you, I tested the indentation.
– Leandro