From 8a31971d473d4ed75eaebe2713046f6b49856ba4 Mon Sep 17 00:00:00 2001 From: Jeslinhashly <91456649+Jeslinhashly@users.noreply.github.com> Date: Mon, 24 Oct 2022 18:43:07 +0530 Subject: [PATCH] shell_short --- shellsort.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 shellsort.py diff --git a/shellsort.py b/shellsort.py new file mode 100644 index 0000000..e5f8b2d --- /dev/null +++ b/shellsort.py @@ -0,0 +1,24 @@ +# Shell sort in python + + +def shellSort(array, n): + + # Rearrange elements at each n/2, n/4, n/8, ... intervals + interval = n // 2 + while interval > 0: + for i in range(interval, n): + temp = array[i] + j = i + while j >= interval and array[j - interval] > temp: + array[j] = array[j - interval] + j -= interval + + array[j] = temp + interval //= 2 + + +data = [9, 8, 3, 7, 5, 6, 4, 1] +size = len(data) +shellSort(data, size) +print('Sorted Array in Ascending Order:') +print(data) \ No newline at end of file