Skip to content

Commit d210cd1

Browse files
Merge pull request matthewsamuel95#622 from francamacdowell/add-shellsort
Added a python implementation of Shell sort algorithm
2 parents 70a2cc5 + e29821d commit d210cd1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Sorting/ShellSort/python/shellsort.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def shell_sort(arr):
2+
3+
# Guess a big gap, then reduce
4+
n = len(arr)
5+
gap = n/2
6+
7+
while gap > 0:
8+
9+
for i in range(gap, n):
10+
11+
temp = arr[i]
12+
j = i
13+
while j >= gap and arr[j-gap] > temp:
14+
arr[j] = arr[j-gap]
15+
j -= gap
16+
17+
arr[j] = temp
18+
gap /= 2
19+
20+
shell_sort(arr)

0 commit comments

Comments
 (0)