Skip to content

Commit 05dd9fe

Browse files
Shell Sort in Python
1 parent c7c62e4 commit 05dd9fe

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sorting/shell-sort.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (C) Deepali Srivastava - All Rights Reserved
2+
# This code is part of DSA course available on CourseGalaxy.com
3+
4+
def shell_sort(a):
5+
h = int(input("Enter maximum increment(odd value) : "))
6+
while h>=1:
7+
for i in range(h,len(a)):
8+
temp = a[i]
9+
j=i-h
10+
while j >= 0 and a[j] > temp:
11+
a[j+h] = a[j]
12+
j=j-h
13+
a[j+h] = temp
14+
h=h-2
15+
16+
##############################################################
17+
18+
list1 = [65,73,21,90,6,239,3,35,1,15,5,9,8,23,12,5,7,2,19,34,]
19+
shell_sort(list1)
20+
print(list1)
21+

0 commit comments

Comments
 (0)