From 67b33a295bc0a18f9fbdeb393724835b2645dbd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E8=BF=9C=E8=B6=85?= Date: Fri, 26 Feb 2021 09:01:50 +0800 Subject: [PATCH] Optimization shell sort (#4119) * optimization * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> --- sorts/shell_sort.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sorts/shell_sort.py b/sorts/shell_sort.py index 2e749e43d..10ae9ba40 100644 --- a/sorts/shell_sort.py +++ b/sorts/shell_sort.py @@ -26,7 +26,8 @@ def shell_sort(collection): while j >= gap and collection[j - gap] > insert_value: collection[j] = collection[j - gap] j -= gap - collection[j] = insert_value + if j != i: + collection[j] = insert_value return collection