From ab2430c9962d57414f3410b84709884b28bbb87a Mon Sep 17 00:00:00 2001 From: pmkfqw2gu <2511089200@qq.com> Date: Thu, 17 Feb 2022 21:33:39 +0800 Subject: [PATCH] =?UTF-8?q?Update=20shell=E6=B3=95.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell法.cpp | 59 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/shell法.cpp b/shell法.cpp index 1c22c13..5f5d896 100644 --- a/shell法.cpp +++ b/shell法.cpp @@ -1,20 +1,41 @@ -void shell(int *a,int n) -{ - int i,j,k,x; - k=n/2; /*���ֵ*/ - while(k>=1) - { - for(i=k;i=0&&x 0; increment /= 2) + { + for (i = increment; i < size; i++) + { + tmp = arr[i]; + for (j = i - increment; j >= 0 && tmp < arr[j]; j -= increment) + { + arr[j + increment] = arr[j]; + } + arr[j + increment] = tmp; + } + } +} +int main() +{ + int arr[] = { 22, 34, 3, 32, 82, 55, 89, 50, 37, 5, 64, 35, 9, 70 }; + int len = (int) sizeof(arr) / sizeof(*arr); + ShellSort(arr, len); + int i; + for (i = 0; i < len; i++) + printf("%d ", arr[i]); + return 0; } + +4.4 运行时间 +0.02275s \ No newline at end of file