From 22355509db2111974b07f148911d538c8f851877 Mon Sep 17 00:00:00 2001 From: Tejas Kashinath <42380254+tejaskashinathofficial@users.noreply.github.com> Date: Sat, 27 Oct 2018 23:28:43 +0530 Subject: [PATCH 1/2] Added Shell Sorting --- sorting/ShellSort.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 sorting/ShellSort.py diff --git a/sorting/ShellSort.py b/sorting/ShellSort.py new file mode 100644 index 0000000..ae2bfd8 --- /dev/null +++ b/sorting/ShellSort.py @@ -0,0 +1,23 @@ +def shellSort(input_list): + + gap = len(input_list) / 2 + while gap > 0: + + for i in range(gap, len(input_list)): + temp = input_list[i] + j = i +# Sort the sub list for this gap + + while j >= gap and input_list[j - gap] > temp: + input_list[j] = input_list[j - gap] + j = j-gap + input_list[j] = temp + +# Reduce the gap for the next element + + gap = gap/2 + +list = [19,2,31,45,30,11,121,27] + +shellSort(list) +print(list) From 1f8d51c973620c333248115b52073b2706342a8c Mon Sep 17 00:00:00 2001 From: Tejas Kashinath <42380254+tejaskashinathofficial@users.noreply.github.com> Date: Sat, 27 Oct 2018 23:31:34 +0530 Subject: [PATCH 2/2] Update tests.py --- tests.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests.py b/tests.py index 270c350..eb230af 100644 --- a/tests.py +++ b/tests.py @@ -55,3 +55,11 @@ print "Bucket Sort incorrect" except: print "Bucketsort function errored or is incomplete" +try: + from ShellSort import ShellSort + if(ShellSort(list(nums)) == sortedNums): + print "Shell Sort success" + else: + print "Shell Sort incorrect" +except: + print "Shell function errored or is incomplete"