Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sorting/shell.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"