Skip to content

Instantly share code, notes, and snippets.

@KyeRussell
Created August 2, 2013 11:04
Show Gist options
  • Save KyeRussell/6139111 to your computer and use it in GitHub Desktop.
Save KyeRussell/6139111 to your computer and use it in GitHub Desktop.
Python bubble sort
set = [1, 6, 2, 1, 21, 8, 34, 9, 9.1, 1, 12, 901, 0.31, -3]
searchable_set = len(set) - 1;
while searchable_set >= 0:
count = 0
while count <= searchable_set - 1:
if set[count] > set[count + 1]:
old = set[count + 1]
set[count + 1] = set[count]
set[count] = old
count = count + 1
searchable_set = searchable_set - 1;
print "Sorted: " + str(set)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment