回答編集履歴
1
加筆
test
CHANGED
@@ -9,3 +9,77 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
はい、できあがり。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
```C
|
16
|
+
|
17
|
+
#include <stdio.h>
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
// x[first~last-1] を反転する
|
22
|
+
|
23
|
+
void reverse(int x[], int first, int last) {
|
24
|
+
|
25
|
+
while ( first < last ) {
|
26
|
+
|
27
|
+
--last;
|
28
|
+
|
29
|
+
int tmp = x[first];
|
30
|
+
|
31
|
+
x[first] = x[last];
|
32
|
+
|
33
|
+
x[last] = tmp;
|
34
|
+
|
35
|
+
++first;
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
// x[first~mid-1] と x[mid~last-1] を入れ替える
|
44
|
+
|
45
|
+
void rotate(int x[], int first, int mid, int last) {
|
46
|
+
|
47
|
+
reverse(x, first, mid);
|
48
|
+
|
49
|
+
reverse(x, mid, last);
|
50
|
+
|
51
|
+
reverse(x, first, last);
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
// x[0~n-1]をプリントする
|
58
|
+
|
59
|
+
void print(int x[], int n) {
|
60
|
+
|
61
|
+
for ( int i = 0; i < n; ++i )
|
62
|
+
|
63
|
+
printf("%d ", x[i]);
|
64
|
+
|
65
|
+
printf("\n");
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
int main() {
|
72
|
+
|
73
|
+
int x[6] = { 1,5,4,3,2,6 };
|
74
|
+
|
75
|
+
print(x,6);
|
76
|
+
|
77
|
+
rotate(x, 0, 2, 6);
|
78
|
+
|
79
|
+
print(x,6);
|
80
|
+
|
81
|
+
return 0;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
```
|