-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
67 lines (65 loc) · 941 Bytes
/
test.cpp
File metadata and controls
67 lines (65 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
using namespace std;
void shell_sort(int a[], int n) {
int h = 1,t;
while (h < n / 3) {
h = 3 * h + 1;
}
while (h >= 1) {
for (int i = h; i < n ;i++)
{
for (int j = i;j >= h && (a[j] < a[j - h]);j -= h) {
t = a[j];
a[j] = a[j - 1];
a[j - 1] = t;
}
}
h = h / 3;
}
}
void insert_sort(int a[], int n) {
int t;
for (int i = 0;i < n;i++) {
int j = i;
while (j>0)
{
if (a[j] < a[j - 1]) {
t = a[j];
a[j] = a[j - 1];
a[j - 1] = t;
j--;
}
else
{
break;
}
}
}
}
void print(){
cout<<"change"<<endl;
cout<<"reconery"<<endl;
cout<<"merge"<<endl;
cout<<"change"<<endl;
}
int main()
{
int n;
int a[100];
int c = n + 1;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
//insert_sort(a, n);
shell_sort(a, n);
for (int i = 0;i < n;i++) {
cout << a[i];
if (i == n - 1) {
cout << endl;
continue;
}
cout << ' ';
}
}