-
-
Save reterVision/a6166fd528d704a22a6d to your computer and use it in GitHub Desktop.
Shell Sort
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
| """ | |
| Shell Sort | |
| """ | |
| def shell_sort(array): | |
| length = len(array) | |
| gap = length / 2 | |
| while gap > 0: | |
| i = 0 | |
| while i < length: | |
| min_index = i | |
| j = i | |
| while j < length: | |
| if array[j] < array[min_index]: | |
| min_index = j | |
| j += gap | |
| if i != min_index: | |
| array[i], array[min_index] = array[min_index], array[i] | |
| i += gap | |
| gap /= 2 | |
| return array | |
| if __name__ == "__main__": | |
| array = [7, 5, 3, 1, 2, 6, 4, 10, 9] | |
| print shell_sort(array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment