From bb6b07817541d2a6d2d1420be278db39007c633d Mon Sep 17 00:00:00 2001 From: KDH Date: Mon, 25 May 2020 16:53:09 +0900 Subject: [PATCH] UPDATE improve shell sort syntax --- sorts/shell_sort.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sorts/shell_sort.py b/sorts/shell_sort.py index 80d95870f95b..bf3c2c7f9cc6 100644 --- a/sorts/shell_sort.py +++ b/sorts/shell_sort.py @@ -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