-
-
Save jiro0402/1cc34620d49849d854ab4348984bf720 to your computer and use it in GitHub Desktop.
Bubble sort in Python
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
def bubble(list): | |
length = len(list) - 1 | |
sorted = False | |
while not sorted: | |
sorted = True | |
for i in range(length): | |
if list[i] > list[i + 1]: | |
sorted = False | |
list[i], list[i + 1] = list[i + 1], list[i] | |
return list | |
print bubble([3, 6, 2, 5, 1, 6, 2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment