Skip to content

Commit c65fa75

Browse files
author
leitao
committed
feat: added shell sort in Python
1 parent e3c1d5e commit c65fa75

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

basic/sorting/ShellSort/ShellSort.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def shellSort(arr):
2+
n = len(arr)
3+
gap = int(n/2)
4+
while gap > 0:
5+
for i in range(gap,n):
6+
temp = arr[i]
7+
j = i
8+
while j >= gap and arr[j-gap] >temp:
9+
arr[j] = arr[j-gap]
10+
j -= gap
11+
arr[j] = temp
12+
gap = int(gap/2)
13+
14+
arr = [ 12, 34, 54, 2, 3]
15+
shellSort(arr)

0 commit comments

Comments
 (0)