Skip to content

Commit 1c57210

Browse files
committed
Implemented Shell Sort in python
1 parent 84e553b commit 1c57210

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ShellSort/Python/ShellSort.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Shell Sort Method
2+
def shell(seq):
3+
inc = len(seq) // 2
4+
while inc:
5+
for i, el in enumerate(seq):
6+
while i >= inc and seq[i - inc] > el:
7+
seq[i] = seq[i - inc]
8+
i -= inc
9+
seq[i] = el
10+
inc = 1 if inc == 2 else int(inc * 5.0 / 11)
11+
12+
data = [22, 7, 2, -5, 8, 4]
13+
shell(data)
14+
print data # [-5, 2, 4, 7, 8, 22]

0 commit comments

Comments
 (0)