回答編集履歴
1
変更箇所を色つけしました。
answer
CHANGED
@@ -102,42 +102,76 @@
|
|
102
102
|
```
|
103
103
|
変更箇所
|
104
104
|
```diff
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
105
|
+
--- goo.org.c 2021-01-29 10:27:02.142726800 +0900
|
106
|
+
+++ goo.c 2021-01-29 10:28:44.316570900 +0900
|
107
|
+
@@ -1,11 +1,13 @@
|
108
|
+
#include <stdio.h>
|
109
|
+
#include <stdlib.h>
|
110
|
+
+#include <string.h>
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
/*昇順のバブルソート*/
|
115
|
+
void bubble_sort1(double a[], int n){
|
116
|
+
- int i,j,t;
|
117
|
+
+ int i,j;
|
118
|
+
+ double t;
|
119
|
+
for(i = 0 ; i < n-1 ; i++){
|
120
|
+
for(j = n-1 ; j > i ; j--){
|
121
|
+
if(a[j-1] > a[j]){
|
122
|
+
@@ -21,7 +23,8 @@
|
123
|
+
|
124
|
+
/*降順のバブルソート*/
|
125
|
+
void bubble_sort2(double a[], int n){
|
126
|
+
- int i,j,t;
|
127
|
+
+ int i,j;
|
128
|
+
+ double t;
|
129
|
+
for(i = 0 ; i < n-1 ; i++){
|
130
|
+
for(j = n-1 ; j > i ; j--){
|
131
|
+
if(a[j] > a[j-1]){
|
132
|
+
@@ -40,7 +43,7 @@
|
133
|
+
char tmp[256];
|
134
|
+
double a[10];
|
135
|
+
double n;
|
136
|
+
- char str ={'+'};
|
137
|
+
+ char str[] = "+";
|
138
|
+
|
139
|
+
/*ファイル入力*/
|
140
|
+
FILE *fp;
|
141
|
+
@@ -53,7 +56,7 @@
|
142
|
+
}
|
143
|
+
|
144
|
+
while(fgets(tmp, sizeof(tmp), fp) != NULL){
|
145
|
+
- n = (double)atoi(tmp);
|
146
|
+
+ n = (double)atof(tmp);
|
147
|
+
a[i] = n;
|
148
|
+
i++;
|
149
|
+
}
|
150
|
+
@@ -64,11 +67,11 @@
|
151
|
+
|
152
|
+
/*昇順・降順を判断する*/
|
153
|
+
if(strcmp(argv[1],str)==0){
|
154
|
+
- bubble_sort1(a,i+1);
|
155
|
+
+ bubble_sort1(a,i);
|
156
|
+
}else{
|
157
|
+
- bubble_sort2(a,i+1);
|
158
|
+
+ bubble_sort2(a,i);
|
159
|
+
}
|
160
|
+
- printf("i\n");
|
161
|
+
+ printf("i=%d\n",i);
|
162
|
+
|
163
|
+
|
164
|
+
/*ファイル出力*/
|
165
|
+
@@ -81,9 +84,8 @@
|
166
|
+
exit(1);
|
167
|
+
}
|
168
|
+
|
169
|
+
- while(a[j] != '\0'){
|
170
|
+
+ for (j =0;j <i;j++){
|
171
|
+
fprintf(outputfile, "%f\n",a[j]);
|
172
|
+
- j++;
|
173
|
+
}
|
174
|
+
|
175
|
+
fclose(outputfile);
|
176
|
+
|
143
177
|
```
|