Last active
December 19, 2015 02:48
-
-
Save nsfyn55/5885231 to your computer and use it in GitHub Desktop.
iterative bubble sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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