diff --git a/sort/shell_sort.py b/sort/shell_sort.py new file mode 100644 index 0000000..1294f8f --- /dev/null +++ b/sort/shell_sort.py @@ -0,0 +1,19 @@ +def shell_sort(arr): + + n = len(arr) + # Initialize size of the gap + gap = n//2 + + while gap > 0: + y_index = gap + while y_index < len(arr): + y = arr[y_index] + x_index = y_index - gap + while x_index >= 0 and y < arr[x_index]: + arr[x_index + gap] = arr[x_index] + x_index = x_index - gap + arr[x_index + gap] = y + y_index = y_index + 1 + gap = gap//2 + + return arr