Skip to content

Instantly share code, notes, and snippets.

@KerryJones
Created January 1, 2016 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KerryJones/2fd3de0f0399c2020bbd to your computer and use it in GitHub Desktop.
Save KerryJones/2fd3de0f0399c2020bbd to your computer and use it in GitHub Desktop.
Python Bubble Sort
def bubble_sort(array):
for i in range(0, len(array)):
swapped = False
for j in range(0, len(array) - i - 1):
if array[j] > array[j + 1]:
array[j], array[j + 1] = array[j + 1], array[j]
swapped = True
if not swapped:
break
return array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment