Created
June 17, 2016 13:06
-
-
Save alenbasic/2b3a8d5c58bbe6fff5a914f992dac684 to your computer and use it in GitHub Desktop.
A slightly refined bubble sort function.
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 bubsort(a): | |
i = len(a) | |
counter = 0 | |
while i > 0: | |
for j in range(len(a)): | |
h = j+1 | |
if h < len(a): | |
if a[j] > a[h]: | |
temp = a[h] | |
a[h] = a[j] | |
a[j] = temp | |
counter += 1 | |
if counter == 0: | |
break | |
else: | |
i -= 1 | |
counter = 0 | |
print a | |
bubsort([1,0,5,9,8,4,7,3,2,6]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment