回答編集履歴
1
変更箇所を色つけしました。
test
CHANGED
@@ -206,80 +206,148 @@
|
|
206
206
|
|
207
207
|
```diff
|
208
208
|
|
209
|
-
2
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
209
|
+
--- goo.org.c 2021-01-29 10:27:02.142726800 +0900
|
210
|
+
|
211
|
+
+++ goo.c 2021-01-29 10:28:44.316570900 +0900
|
212
|
+
|
213
|
+
@@ -1,11 +1,13 @@
|
214
|
+
|
215
|
+
#include <stdio.h>
|
216
|
+
|
217
|
+
#include <stdlib.h>
|
218
|
+
|
219
|
+
+#include <string.h>
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
/*昇順のバブルソート*/
|
228
|
+
|
229
|
+
void bubble_sort1(double a[], int n){
|
230
|
+
|
231
|
+
- int i,j,t;
|
232
|
+
|
233
|
+
+ int i,j;
|
234
|
+
|
235
|
+
+ double t;
|
236
|
+
|
237
|
+
for(i = 0 ; i < n-1 ; i++){
|
238
|
+
|
239
|
+
for(j = n-1 ; j > i ; j--){
|
240
|
+
|
241
|
+
if(a[j-1] > a[j]){
|
242
|
+
|
243
|
+
@@ -21,7 +23,8 @@
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
/*降順のバブルソート*/
|
248
|
+
|
249
|
+
void bubble_sort2(double a[], int n){
|
250
|
+
|
251
|
+
- int i,j,t;
|
252
|
+
|
253
|
+
+ int i,j;
|
254
|
+
|
255
|
+
+ double t;
|
256
|
+
|
257
|
+
for(i = 0 ; i < n-1 ; i++){
|
258
|
+
|
259
|
+
for(j = n-1 ; j > i ; j--){
|
260
|
+
|
261
|
+
if(a[j] > a[j-1]){
|
262
|
+
|
263
|
+
@@ -40,7 +43,7 @@
|
264
|
+
|
265
|
+
char tmp[256];
|
266
|
+
|
267
|
+
double a[10];
|
268
|
+
|
269
|
+
double n;
|
270
|
+
|
271
|
+
- char str ={'+'};
|
272
|
+
|
273
|
+
+ char str[] = "+";
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
/*ファイル入力*/
|
278
|
+
|
279
|
+
FILE *fp;
|
280
|
+
|
281
|
+
@@ -53,7 +56,7 @@
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
while(fgets(tmp, sizeof(tmp), fp) != NULL){
|
288
|
+
|
289
|
+
- n = (double)atoi(tmp);
|
290
|
+
|
291
|
+
+ n = (double)atof(tmp);
|
292
|
+
|
293
|
+
a[i] = n;
|
294
|
+
|
295
|
+
i++;
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
@@ -64,11 +67,11 @@
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
/*昇順・降順を判断する*/
|
304
|
+
|
305
|
+
if(strcmp(argv[1],str)==0){
|
306
|
+
|
307
|
+
- bubble_sort1(a,i+1);
|
308
|
+
|
309
|
+
+ bubble_sort1(a,i);
|
310
|
+
|
311
|
+
}else{
|
312
|
+
|
313
|
+
- bubble_sort2(a,i+1);
|
314
|
+
|
315
|
+
+ bubble_sort2(a,i);
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
- printf("i\n");
|
320
|
+
|
321
|
+
+ printf("i=%d\n",i);
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
/*ファイル出力*/
|
328
|
+
|
329
|
+
@@ -81,9 +84,8 @@
|
330
|
+
|
331
|
+
exit(1);
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
- while(a[j] != '\0'){
|
338
|
+
|
339
|
+
+ for (j =0;j <i;j++){
|
340
|
+
|
341
|
+
fprintf(outputfile, "%f\n",a[j]);
|
342
|
+
|
343
|
+
- j++;
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
fclose(outputfile);
|
350
|
+
|
351
|
+
|
284
352
|
|
285
353
|
```
|