Skip to content

Instantly share code, notes, and snippets.

@marcoscastro
Last active November 9, 2019 07:05
Show Gist options
  • Select an option

  • Save marcoscastro/b8882b5faa846ca44116ba8be2384e33 to your computer and use it in GitHub Desktop.

Select an option

Save marcoscastro/b8882b5faa846ca44116ba8be2384e33 to your computer and use it in GitHub Desktop.
Curso Python 300 - Aula 30 - Bubble Sort
'''
Implementação do Algoritmo Bubble Sort
Animação: https://www.youtube.com/watch?v=lyZQPjUT5B4
'''
l = [30, 50, 10, 35, 70, 45, 80, 100, 22]
tam_l = len(l)
# bubble sort
for i in range(tam_l):
troca = False
for j in range(1, tam_l - i):
if l[j] < l[j - 1]:
l[j], l[j - 1] = l[j - 1], l[j]
troca = True
if not troca:
break
print(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment