From d521dcca40534e82171f8f5883bdc001018453d7 Mon Sep 17 00:00:00 2001 From: Prathima Kadari Date: Sat, 15 May 2021 19:43:50 +0530 Subject: [PATCH] Added shell short program in python --- sort/shell_sort.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sort/shell_sort.py 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