Skip to content

Instantly share code, notes, and snippets.

@tuvo1106
Last active July 4, 2019 17:14
Show Gist options
  • Save tuvo1106/b86b42dab0fa9ac15af9e145bd99fe41 to your computer and use it in GitHub Desktop.
Save tuvo1106/b86b42dab0fa9ac15af9e145bd99fe41 to your computer and use it in GitHub Desktop.
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