Skip to content

Commit a8f4b08

Browse files
committed
Sorting
1 parent 1385f8a commit a8f4b08

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sorting/ShellSort.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def shellsort(A):
2+
n = len(A)
3+
gap = n//2
4+
while gap > 0:
5+
i = gap
6+
while i < n:
7+
temp = A[i]
8+
j = i - gap
9+
while j >= 0 and A[j] > temp:
10+
A[j+gap] = A[j]
11+
j = j - gap
12+
A[j+gap] = temp
13+
i = i + 1
14+
gap = gap // 2
15+
16+
17+
A = [3, 5, 8, 9, 6, 2]
18+
print('Original Array:',A)
19+
shellsort(A)
20+
print('Sorted Array:',A)

0 commit comments

Comments
 (0)