From d4a34a585c00544de55fbd18ac5ddb6fe6711444 Mon Sep 17 00:00:00 2001 From: Rain120 <1085131904@qq.com> Date: Mon, 31 Jan 2022 17:15:50 +0800 Subject: [PATCH 1/2] Update 4.shellSort.md --- 4.shellSort.md | 1 + 1 file changed, 1 insertion(+) diff --git a/4.shellSort.md b/4.shellSort.md index e6d5f9c..bcd5593 100644 --- a/4.shellSort.md +++ b/4.shellSort.md @@ -9,6 +9,7 @@ 希尔排序的基本思想是:先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录“基本有序”时,再对全体记录进行依次直接插入排序。 +![image](https://user-images.githubusercontent.com/20939839/151767449-ea226730-9e45-4eb2-b246-70d9f1e0fed3.png) ## 1. 算法步骤 From 750dbfdce7642b7689175546abbb752dd7db578f Mon Sep 17 00:00:00 2001 From: Rain120 <1085131904@qq.com> Date: Mon, 31 Jan 2022 17:24:43 +0800 Subject: [PATCH 2/2] Update 4.shellSort.md --- 4.shellSort.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/4.shellSort.md b/4.shellSort.md index bcd5593..6b6778a 100644 --- a/4.shellSort.md +++ b/4.shellSort.md @@ -27,16 +27,19 @@ function shellSort(arr) { var len = arr.length, temp, gap = 1; - while(gap < len/3) { //动态定义间隔序列 - gap =gap*3+1; + while(gap < len / 3) { //动态定义间隔序列 + gap = gap * 3 + 1; } - for (gap; gap > 0; gap = Math.floor(gap/3)) { + for (gap; gap > 0; gap = Math.floor(gap / 3)) { for (var i = gap; i < len; i++) { temp = arr[i]; - for (var j = i-gap; j >= 0 && arr[j] > temp; j-=gap) { - arr[j+gap] = arr[j]; + var j = i - gap; + + for (; j >= 0 && arr[j] > temp; j -= gap) { + arr[j + gap] = arr[j]; } - arr[j+gap] = temp; + + arr[j + gap] = temp; } } return arr;