Skip to content

Instantly share code, notes, and snippets.

@nsfyn55
Last active December 19, 2015 02:48
Show Gist options
  • Save nsfyn55/5885231 to your computer and use it in GitHub Desktop.
Save nsfyn55/5885231 to your computer and use it in GitHub Desktop.
iterative bubble sort
def sort(l):
for x in range(len(l)-1):
for i in range(len(l)-(x+1)):
if l[i] > l[i+ 1]:
swap(l, i, i+1)
return l
def swap(l, index1, index2):
buff = l[index1]
l[index1] = l[index2]
l[index2] = buff
l = [4, 78, 54, 2, 1, 1, 4, 15, 18, 7, 9, 2, 18]
print sort(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment