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
23 changes: 23 additions & 0 deletions sorting/ShellSort.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"