Skip to content

Commit 4768735

Browse files
authored
Enhance shell sort syntax (TheAlgorithms#2035)
1 parent 0e61906 commit 4768735

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

sorts/shell_sort.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,11 @@ def shell_sort(collection):
3030
gaps = [701, 301, 132, 57, 23, 10, 4, 1]
3131

3232
for gap in gaps:
33-
i = gap
34-
while i < len(collection):
35-
temp = collection[i]
33+
for i in range(gap, len(collection)):
3634
j = i
37-
while j >= gap and collection[j - gap] > temp:
38-
collection[j] = collection[j - gap]
35+
while j >= gap and collection[j] < collection[j - gap]:
36+
collection[j], collection[j - gap] = collection[j - gap], collection[j]
3937
j -= gap
40-
collection[j] = temp
41-
i += 1
42-
4338
return collection
4439

4540

0 commit comments

Comments
 (0)