Enhance shell sort syntax (#2035)

This commit is contained in:
KDH 2020-05-26 11:18:03 +09:00 committed by GitHub
parent 0e619065e7
commit 4768735668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,16 +30,11 @@ def shell_sort(collection):
gaps = [701, 301, 132, 57, 23, 10, 4, 1]
for gap in gaps:
i = gap
while i < len(collection):
temp = collection[i]
for i in range(gap, len(collection)):
j = i
while j >= gap and collection[j - gap] > temp:
collection[j] = collection[j - gap]
while j >= gap and collection[j] < collection[j - gap]:
collection[j], collection[j - gap] = collection[j - gap], collection[j]
j -= gap
collection[j] = temp
i += 1
return collection