From 2bda94bd12abd183973224d4f927c3930fc21536 Mon Sep 17 00:00:00 2001 From: pn43tqvrm <2516333959@qq.com> Date: Sat, 19 Feb 2022 16:11:38 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E5=B8=8C=E5=B0=94=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 希尔排序 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 希尔排序 diff --git a/希尔排序 b/希尔排序 new file mode 100644 index 0000000..3052f16 --- /dev/null +++ b/希尔排序 @@ -0,0 +1,35 @@ +//希尔排序 +void shellSort(vectorv) +{ + cout << "希尔排序,升序:" << endl; + + int gap = v.size(); + + while (gap != 1) + { + gap = gap / 3 + 1; + + for (int i = gap; i = 0; j -= gap) + { + if (v[j] > temp) + { + v[j + gap] = v[j]; + } + else + { + break; + } + } + + v[j + gap] = temp; + } + } + + printVector(v); +} +//复杂度说明:时间复杂度为O(n^1.5) \ No newline at end of file