diff --git a/sorting/shell.py b/sorting/shell.py new file mode 100644 index 0000000..585e07c --- /dev/null +++ b/sorting/shell.py @@ -0,0 +1,16 @@ +def shellSort(numbers): + + gap = len(numbers) // 2 + while gap > 0: + + for i in range(gap, len(numbers)): + temp = numbers[i] + j = i +# Sort the sub list for this gap + while j >= gap and numbers[j - gap] > temp: + numbers[j] = numbers[j - gap] + j = j-gap + numbers[j] = temp +# Reduce the gap for the next element + gap = gap//2 + return numbers diff --git a/tests.py b/tests.py index 270c350..f19758b 100644 --- a/tests.py +++ b/tests.py @@ -55,3 +55,12 @@ print "Bucket Sort incorrect" except: print "Bucketsort function errored or is incomplete" + +try: + from shell import shell + if(shell(list(nums)) == sortedNums): + print "Shell Sort success" + else: + print "Shell Sort incorrect" +except: + print "Shell sort function errored or is incomplete" \ No newline at end of file