Last active
November 9, 2019 07:05
-
-
Save marcoscastro/b8882b5faa846ca44116ba8be2384e33 to your computer and use it in GitHub Desktop.
Curso Python 300 - Aula 30 - Bubble Sort
This file contains hidden or 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
| ''' | |
| 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