We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fa474f1 commit 630a420Copy full SHA for 630a420
shell_sort.cpp
@@ -0,0 +1,43 @@
1
+#include <cstdio>
2
+
3
+#define ELEMENT_COUNT 100000
4
5
+using namespace std;
6
7
+int n, d[ELEMENT_COUNT];
8
9
+void Shell_sort()
10
+{
11
+ for (int gc = n >> 1; gc >= 1; gc >>= 1)
12
+ {
13
+ for (int s = 0; s < gc; s++)
14
15
+ for (int i = s; i < n; i += gc)
16
17
+ for (int j = i - gc; j >= 0 && d[j] > d[j + gc]; j -= gc)
18
19
+ int temp = d[j];
20
+ d[j] = d[j + gc];
21
+ d[j + gc] = temp;
22
+ }
23
24
25
26
+}
27
28
+int main()
29
30
+ scanf("%d", &n);
31
+ for (int i = 0; i < n; i++)
32
33
+ scanf("%d", &d[i]);
34
35
+ Shell_sort();
36
37
38
+ printf("%d ", d[i]);
39
40
+ return 0;
41
42
43
0 commit comments