Skip to content

Commit cacc19e

Browse files
authored
shell
1 parent 743b8a8 commit cacc19e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

shell_sort.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#Shell Sort
2+
3+
def shell_sort(arr):
4+
n = len(arr)
5+
gap = n//2
6+
7+
while gap > 0:
8+
for i in range(gap, n):
9+
temp = arr[i]
10+
j = i
11+
12+
while j >= gap and arr[j-gap] > temp:
13+
arr[j] = arr[j-gap]
14+
j -= gap
15+
16+
arr[j] = temp
17+
gap = gap//2
18+
19+
return arr
20+
21+
arr = [64, 34, 25, 12, 22, 11, 90]
22+
23+
print("Sorted array is:", shell_sort(arr))

0 commit comments

Comments
 (0)