回答編集履歴
2
変更
answer
CHANGED
@@ -227,19 +227,19 @@
|
|
227
227
|
struct data* r = list;
|
228
228
|
while (1){
|
229
229
|
if(strcmp(p->name,node->name)>0){
|
230
|
-
|
230
|
+
node->next=p;
|
231
231
|
if(r==list){
|
232
|
-
|
232
|
+
list=node;
|
233
|
-
|
233
|
+
}else{
|
234
|
-
|
234
|
+
r->next=node;
|
235
|
-
|
235
|
+
}
|
236
236
|
break;
|
237
|
-
|
237
|
+
}
|
238
238
|
if (p->next==NULL){
|
239
|
-
|
239
|
+
p->next=node;
|
240
|
-
|
240
|
+
break;
|
241
|
-
|
241
|
+
}
|
242
|
-
|
242
|
+
r = p;
|
243
243
|
p = p->next;
|
244
244
|
}
|
245
245
|
}
|
1
追加
answer
CHANGED
@@ -157,4 +157,106 @@
|
|
157
157
|
printf("登録者数は%dです\n",total);
|
158
158
|
}
|
159
159
|
|
160
|
+
```
|
161
|
+
|
162
|
+
ポインタの連結をソート版も作成してみました。
|
163
|
+
```c
|
164
|
+
#include<stdio.h>
|
165
|
+
#include<string.h>
|
166
|
+
#include<stdlib.h>
|
167
|
+
|
168
|
+
struct data{
|
169
|
+
char name[256];
|
170
|
+
char mail[256];
|
171
|
+
int group;
|
172
|
+
int ID;
|
173
|
+
struct data *next;
|
174
|
+
};
|
175
|
+
|
176
|
+
struct data* new_data(struct data* list, int n);
|
177
|
+
void list_output(struct data* p);
|
178
|
+
|
179
|
+
int main(void){
|
180
|
+
|
181
|
+
struct data *list = NULL;
|
182
|
+
int i=1;
|
183
|
+
int n=1;
|
184
|
+
|
185
|
+
while(i){
|
186
|
+
list = new_data(list, n++);
|
187
|
+
scanf("%d",&i);
|
188
|
+
}
|
189
|
+
|
190
|
+
list_output(list);
|
191
|
+
return 0;
|
192
|
+
}
|
193
|
+
|
194
|
+
struct data* new_data(struct data* list, int n){
|
195
|
+
char check[256];
|
196
|
+
int a,b=0;
|
197
|
+
|
198
|
+
struct data* node = (struct data*)malloc(sizeof(struct data));
|
199
|
+
printf("データを入力してください。\n");
|
200
|
+
printf("name:");
|
201
|
+
scanf("%s",node->name);
|
202
|
+
printf("mail:");
|
203
|
+
scanf("%s",node->mail);
|
204
|
+
|
205
|
+
while(b!=1){
|
206
|
+
printf("group:");
|
207
|
+
scanf("%s",check);
|
208
|
+
a=0;
|
209
|
+
b=1;
|
210
|
+
while(check[a]!='\0'&& check[a] != '\n'){
|
211
|
+
if(check[a]<'0' || '9'<check[a]){
|
212
|
+
b=0;
|
213
|
+
printf("数字を入力してください。\n");break;
|
214
|
+
}
|
215
|
+
a++;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
node->group = atoi(check);
|
219
|
+
node->ID = n;
|
220
|
+
node->next = NULL;
|
221
|
+
|
222
|
+
if(list == NULL){
|
223
|
+
list = node;
|
224
|
+
}
|
225
|
+
else{
|
226
|
+
struct data* p = list;
|
227
|
+
struct data* r = list;
|
228
|
+
while (1){
|
229
|
+
if(strcmp(p->name,node->name)>0){
|
230
|
+
node->next=p;
|
231
|
+
if(r==list){
|
232
|
+
list=node;
|
233
|
+
}else{
|
234
|
+
r->next=node;
|
235
|
+
}
|
236
|
+
break;
|
237
|
+
}
|
238
|
+
if (p->next==NULL){
|
239
|
+
p->next=node;
|
240
|
+
break;
|
241
|
+
}
|
242
|
+
r = p;
|
243
|
+
p = p->next;
|
244
|
+
}
|
245
|
+
}
|
246
|
+
return list;
|
247
|
+
}
|
248
|
+
|
249
|
+
void list_output(struct data *p){
|
250
|
+
int total=0;
|
251
|
+
while(p!=NULL){
|
252
|
+
|
253
|
+
printf("%s %s %d %d\n",p->name,p->mail,p->group,p->ID);
|
254
|
+
total++;
|
255
|
+
if(p->next == NULL)
|
256
|
+
break;
|
257
|
+
p=p->next;
|
258
|
+
|
259
|
+
}
|
260
|
+
printf("登録者数は%dです\n",total);
|
261
|
+
}
|
160
262
|
```
|