Skip to content
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Algorithms covered so far:
| Insertion Sort | insertion_sort |
| Heap Sort | heap_sort |
| Merge Sort | merge_sort |
| Shell Sort | shell_sort |

# Usage:

Expand Down
16 changes: 16 additions & 0 deletions sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,19 @@ def _quick_sort(items, low, high):
_quick_sort(items, split_index + 1, high)

_quick_sort(nums, 0, nums.get_len() - 1)
def shell_sort(nums):

n=nums.get_len()
gap=n//2

while gap>0:

for i in range(gap,n):
temp=nums[i]
j=i
while j>=gap and nums[j-gap]>temp:
nums[j]=nums[j-gap]
j-=gap

nums[j]=temp
gap //= 2
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def test(sorting_function):


functions = [s.bubble_sort, s.heap_sort, s.selection_sort,
s.insertion_sort, s.quick_sort, s.merge_sort]
s.insertion_sort, s.quick_sort, s.merge_sort, s.shell_sort]
for function in functions:
print('Testing: ', function.__name__.ljust(16), test(function))