Skip to content

Instantly share code, notes, and snippets.

@jiro0402
Forked from daGrevis/bubble.py
Created January 10, 2019 08:04
Show Gist options
  • Save jiro0402/1cc34620d49849d854ab4348984bf720 to your computer and use it in GitHub Desktop.
Save jiro0402/1cc34620d49849d854ab4348984bf720 to your computer and use it in GitHub Desktop.
Bubble sort in Python
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