Created
October 17, 2018 06:32
-
-
Save scientificRat/a86ad55e837701cf6511e26c8b1f3573 to your computer and use it in GitHub Desktop.
shell-sort implementation in python
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 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