From 47687356689615317d4f5f9cb846abec320f84bf Mon Sep 17 00:00:00 2001 From: KDH Date: Tue, 26 May 2020 11:18:03 +0900 Subject: [PATCH] Enhance shell sort syntax (#2035) --- 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 80d95870f..bf3c2c7f9 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