質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,561 @@
|
|
1
1
|
cc -Wall -W ファイル名
|
2
2
|
|
3
3
|
でコンパイルした際、宣言して使っているにも関わらずコンパイル時に「使用されない変数」と出てきてしまいます。原因として考えられるのはどんなことですか?-Dオプションを使っているのですが、関係はあるのでしょうか?
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
### 該当のソースコード
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```c
|
12
|
+
|
13
|
+
#include <stdio.h>
|
14
|
+
|
15
|
+
#include <stdlib.h>
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
#ifdef hairetsu_riyou
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
void bubble_sort_array(int a[], int n);
|
24
|
+
|
25
|
+
void selection_sort_array(int a[], int n);
|
26
|
+
|
27
|
+
void insertion_sort_array(int a[], int n);
|
28
|
+
|
29
|
+
void shell_sort_array(int a[], int n);
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
#else
|
34
|
+
|
35
|
+
typedef struct {
|
36
|
+
|
37
|
+
int key;
|
38
|
+
|
39
|
+
int data;
|
40
|
+
|
41
|
+
}kozotai;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
void bubble_sort_kozotai(kozotai a[] , int n);
|
46
|
+
|
47
|
+
void selection_sort_kozotai(kozotai a[] , int n);
|
48
|
+
|
49
|
+
void insertion_sort_kozotai(kozotai a[] , int n);
|
50
|
+
|
51
|
+
void shell_sort_kozotai(kozotai a[], int n);
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
#endif
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
int main(void){
|
60
|
+
|
61
|
+
int i, tmp;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
int n=100;
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
#ifdef hairetsu_riyou
|
70
|
+
|
71
|
+
int hairetsu[100]={412, 54, 595, 329, 24, 488, 313, 272, 129, 210,
|
72
|
+
|
73
|
+
670, 516, 342, 541, 491, 640, 167, 117, 726, 206,
|
74
|
+
|
75
|
+
474, 762, 153, 292, 1000, 607, 151, 661, 93, 270,
|
76
|
+
|
77
|
+
737, 531, 641, 548, 299, 287, 547, 394, 550, 474,
|
78
|
+
|
79
|
+
443, 261, 707, 503, 403, 739, 226, 646, 778, 588,
|
80
|
+
|
81
|
+
427, 169, 477, 572, 412, 299, 88, 321, 54, 778,
|
82
|
+
|
83
|
+
541, 680, 210, 272, 288, 276, 405, 307, 424, 668,
|
84
|
+
|
85
|
+
756, 255, 190, 449, 35, 435, 91, 486, 58, 408,
|
86
|
+
|
87
|
+
4, 63, 534, 329, 701, 65, 256, 311, 586, 403,
|
88
|
+
|
89
|
+
459, 254, 291, 333, 42, 343, 418, 512, 164, 56};
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
for(i=0;i<n;i++){
|
94
|
+
|
95
|
+
printf("hairetsu[%d]= %d\n" , i, hairetsu[i]);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
#ifdef BUB
|
102
|
+
|
103
|
+
bubble_sort_array(hairetsu ,n);
|
104
|
+
|
105
|
+
#endif
|
106
|
+
|
107
|
+
#ifdef SEL
|
108
|
+
|
109
|
+
selection_sort_array(hairetsu, n);
|
110
|
+
|
111
|
+
#endif
|
112
|
+
|
113
|
+
#ifdef INS
|
114
|
+
|
115
|
+
insertion_sort_array(hairetsu, n);
|
116
|
+
|
117
|
+
#endif
|
118
|
+
|
119
|
+
#ifdef SHL
|
120
|
+
|
121
|
+
shell_sort_array(hairetsu, n);
|
122
|
+
|
123
|
+
#endif
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
printf("\n\nソート後\n\n");
|
128
|
+
|
129
|
+
for(i=0;i<n;i++){
|
130
|
+
|
131
|
+
printf("hairetsu[%d]= %d\n" , i, hairetsu[i]);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
tmp = hairetsu[9]; hairetsu[9] = hairetsu[89]; hairetsu[89] = tmp;
|
138
|
+
|
139
|
+
tmp = hairetsu[49]; hairetsu[49] = hairetsu[59]; hairetsu[59] = tmp;
|
140
|
+
|
141
|
+
printf("\n\nほぼソート済\n\n");
|
142
|
+
|
143
|
+
for(i=0;i<n;i++){
|
144
|
+
|
145
|
+
printf("hairetsu[%d]= %d\n" , i, hairetsu[i]);
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
#ifdef BUB
|
150
|
+
|
151
|
+
bubble_sort_array(hairetsu ,n);
|
152
|
+
|
153
|
+
#endif
|
154
|
+
|
155
|
+
#ifdef SEL
|
156
|
+
|
157
|
+
selection_sort_array(hairetsu, n);
|
158
|
+
|
159
|
+
#endif
|
160
|
+
|
161
|
+
#ifdef INS
|
162
|
+
|
163
|
+
insertion_sort_array(hairetsu, n);
|
164
|
+
|
165
|
+
#endif
|
166
|
+
|
167
|
+
#ifdef SHL
|
168
|
+
|
169
|
+
shell_sort_array(hairetsu, n);
|
170
|
+
|
171
|
+
#endif
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
printf("\n\nソート後\n\n");
|
176
|
+
|
177
|
+
for(i=0;i<n;i++){
|
178
|
+
|
179
|
+
printf("hairetsu[%d]= %d\n" , i, hairetsu[i]);
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
#else
|
190
|
+
|
191
|
+
kozotai table[100];
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
for(i=0;i<n;i++){
|
196
|
+
|
197
|
+
table[i].key=i;
|
198
|
+
|
199
|
+
table[i].data=rand()%893;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
for(i=0;i<n;i++){
|
206
|
+
|
207
|
+
printf("table[%d].key= %d table[%d].data= %d\n" , i, table[i].key, i, table[i].data);
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
#ifdef BUB
|
214
|
+
|
215
|
+
bubble_sort_kozotai(table, n);
|
216
|
+
|
217
|
+
#endif
|
218
|
+
|
219
|
+
#ifdef SEL
|
220
|
+
|
221
|
+
selection_sort_kozotai(table, n);
|
222
|
+
|
223
|
+
#endif
|
224
|
+
|
225
|
+
#ifdef INS
|
226
|
+
|
227
|
+
insertion_sort_kozotai(table, n);
|
228
|
+
|
229
|
+
#endif
|
230
|
+
|
231
|
+
#ifdef SHE
|
232
|
+
|
233
|
+
shell_sort_kozotai(table, n);
|
234
|
+
|
235
|
+
#endif
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
printf("\n\nソート後\n\n");
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
for(i=0;i<n;i++){
|
244
|
+
|
245
|
+
printf("table[%d].key= %d table[%d].data= %d\n" , i, table[i].key, i, table[i].data);
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
#endif
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
return 0;
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
#if hairetsu_riyou
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
void bubble_sort_array(int a[], int n);
|
268
|
+
|
269
|
+
int i, j, t;
|
270
|
+
|
271
|
+
for (i = 0; i < n-1; i++) {
|
272
|
+
|
273
|
+
j = n;
|
274
|
+
|
275
|
+
while (j > i) {
|
276
|
+
|
277
|
+
if (a[j-1] > a[j]) {
|
278
|
+
|
279
|
+
t = a[j];
|
280
|
+
|
281
|
+
a[j] = a[j-1];
|
282
|
+
|
283
|
+
a[j-1] = t;
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
j--;
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
void selection_sort_array(int a[], int n){
|
300
|
+
|
301
|
+
int i, j, t, lowest, lowkey;
|
302
|
+
|
303
|
+
for (i = 0; i < n-1; i++) {
|
304
|
+
|
305
|
+
lowest = i;
|
306
|
+
|
307
|
+
lowkey = a[i];
|
308
|
+
|
309
|
+
for (j = i+1; j < n; j++) {
|
310
|
+
|
311
|
+
if (lowkey > a[j]) {
|
312
|
+
|
313
|
+
lowest = j;
|
314
|
+
|
315
|
+
lowkey = a[j];
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
t = a[lowest];
|
320
|
+
|
321
|
+
a[lowest] = a[i];
|
322
|
+
|
323
|
+
a[i] = t;
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
void insertion_sort_array(int a[], int n){
|
334
|
+
|
335
|
+
int i, j, t;
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
for(i=1; i<n; i++ ){
|
340
|
+
|
341
|
+
j=i;
|
342
|
+
|
343
|
+
while(j>=1 && a[j-1] >a[j]){
|
344
|
+
|
345
|
+
t = a[j];
|
346
|
+
|
347
|
+
a[j]=a[j-1];
|
348
|
+
|
349
|
+
a[j-1]=t;
|
350
|
+
|
351
|
+
j--;
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
void shell_sort_array(int a[], int n){
|
362
|
+
|
363
|
+
int i, j, k, t, w, hikaku=0, koukan=0;
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
t = n / 2;
|
368
|
+
|
369
|
+
while (t > 0) {
|
370
|
+
|
371
|
+
for (i = 1; i <= t; i++) {
|
372
|
+
|
373
|
+
for (j = i + t; i <= n; j = j + t) {
|
374
|
+
|
375
|
+
w = a[j];
|
376
|
+
|
377
|
+
k = j - t;
|
378
|
+
|
379
|
+
while (k > 0) {
|
380
|
+
|
381
|
+
if (a[k] <= w) {break;}
|
382
|
+
|
383
|
+
a[k+t] = a[k];
|
384
|
+
|
385
|
+
k = k - t;
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
a[k+t] = w;
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
t = t / 2;
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
#else
|
404
|
+
|
405
|
+
void bubble_sort_kozotai(kozotai a[], int n){
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
int i, j;
|
410
|
+
|
411
|
+
kozotai t;
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
for (i = 0; i < n-1; i++) {
|
416
|
+
|
417
|
+
j = n;
|
418
|
+
|
419
|
+
while (j > i) {
|
420
|
+
|
421
|
+
if (a[j-1].data > a[j].data) {
|
422
|
+
|
423
|
+
t = a[j];
|
424
|
+
|
425
|
+
a[j] = a[j-1];
|
426
|
+
|
427
|
+
a[j-1] = t;
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
j--;
|
432
|
+
|
433
|
+
}
|
434
|
+
|
435
|
+
}
|
436
|
+
|
437
|
+
}
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
void selection_sort_kozotai(kozotai a[], int n){
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
int i, j, lowest, lowkey;
|
446
|
+
|
447
|
+
kozotai t;
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
for (i = 0; i < n-1; i++) {
|
452
|
+
|
453
|
+
lowest = i;
|
454
|
+
|
455
|
+
lowkey = a[i].data;
|
456
|
+
|
457
|
+
for (j = i+1; j < n; j++) {
|
458
|
+
|
459
|
+
if (a[lowest].data > a[j].data) {
|
460
|
+
|
461
|
+
lowest = j;
|
462
|
+
|
463
|
+
lowkey = a[j].data;
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
t = a[lowest];
|
470
|
+
|
471
|
+
a[lowest] = a[i];
|
472
|
+
|
473
|
+
a[i] = t;
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
}
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
void insertion_sort_kozotai(kozotai a[], int n){
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
int i, j;
|
486
|
+
|
487
|
+
kozotai t;
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
for(i=1; i<n; i++ ){
|
492
|
+
|
493
|
+
j=i;
|
494
|
+
|
495
|
+
while(j>=1 && a[j-1].data >a[j].data){
|
496
|
+
|
497
|
+
t = a[j];
|
498
|
+
|
499
|
+
a[j]=a[j-1];
|
500
|
+
|
501
|
+
a[j-1]=t;
|
502
|
+
|
503
|
+
j--;
|
504
|
+
|
505
|
+
}
|
506
|
+
|
507
|
+
}
|
508
|
+
|
509
|
+
}
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
void shell_sort_kozotai(kozotai a[], int n){
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
int i, j, k, t;
|
518
|
+
|
519
|
+
kozotai w;
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
t = n / 2;
|
524
|
+
|
525
|
+
while (t > 0) {
|
526
|
+
|
527
|
+
for (i = 1; i <= t; i++) {
|
528
|
+
|
529
|
+
for (j = i + t; i <= n; j = j + t) {
|
530
|
+
|
531
|
+
w = a[j];
|
532
|
+
|
533
|
+
k = j - t;
|
534
|
+
|
535
|
+
while (k > 0) {
|
536
|
+
|
537
|
+
if (a[k].data <= w.data) {break;}
|
538
|
+
|
539
|
+
a[k+t] = a[k];
|
540
|
+
|
541
|
+
k = k - t;
|
542
|
+
|
543
|
+
}
|
544
|
+
|
545
|
+
a[k+t] = w;
|
546
|
+
|
547
|
+
}
|
548
|
+
|
549
|
+
}
|
550
|
+
|
551
|
+
t = t / 2;
|
552
|
+
|
553
|
+
}
|
554
|
+
|
555
|
+
}
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
#endif
|
560
|
+
|
561
|
+
```
|