Skip to content

Instantly share code, notes, and snippets.

@scientificRat
Created October 17, 2018 06:32
Show Gist options
  • Save scientificRat/a86ad55e837701cf6511e26c8b1f3573 to your computer and use it in GitHub Desktop.
Save scientificRat/a86ad55e837701cf6511e26c8b1f3573 to your computer and use it in GitHub Desktop.
shell-sort implementation in python
def shell_sort(array):
gap = len(array) // 2
while gap > 0:
for i in range(gap, len(array)):
for j in range(i - gap, -1, -1):
if array[j] <= array[j + gap]:
break
tmp = array[j]
array[j] = array[j + gap]
array[j + gap] = tmp
gap //= 2
return array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment