Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 3, 2014 23:43
Show Gist options
  • Save globby/9337097 to your computer and use it in GitHub Desktop.
Save globby/9337097 to your computer and use it in GitHub Desktop.
The Bubble Sort algorithm
def bubble(a):
if len(a) < 2: return
for i in range(0,len(a)):
swapped = False
for j in range(len(a)-1,i+1,-1):
if a[j] < a[j-1]:
a[j], a[j-1], swapped = a[j-1], a[j], True
if not swapped: break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment