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) 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"