Last active
July 4, 2019 17:14
-
-
Save tuvo1106/b86b42dab0fa9ac15af9e145bd99fe41 to your computer and use it in GitHub Desktop.
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 shaker(l:list): | |
arr = l[::] | |
sort = True | |
start = 0 | |
end = len(arr) | |
while (sort): | |
sort = False | |
for i in range(start, end): | |
if arr[i] < arr[i - 1]: | |
arr[i], arr[i - 1] = arr[i-1], arr[i] | |
sort = True | |
if not sort: | |
break | |
for j in range(end - 1, start, -1): | |
if arr[j] < arr[j - 1]: | |
arr[j], arr[j - 1] = arr[j - 1], arr[j] | |
sort = True | |
start += 1 | |
end -= 1 | |
return arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment