回答編集履歴

2

変更

2017/05/22 23:16

投稿

A.Ichi
A.Ichi

スコア4070

test CHANGED
@@ -456,31 +456,31 @@
456
456
 
457
457
  if(strcmp(p->name,node->name)>0){
458
458
 
459
- node->next=p;
459
+ node->next=p;
460
460
 
461
461
  if(r==list){
462
462
 
463
- list=node;
463
+ list=node;
464
-
464
+
465
- }else{
465
+ }else{
466
-
466
+
467
- r->next=node;
467
+ r->next=node;
468
-
468
+
469
- }
469
+ }
470
470
 
471
471
  break;
472
472
 
473
- }
473
+ }
474
474
 
475
475
  if (p->next==NULL){
476
476
 
477
- p->next=node;
477
+ p->next=node;
478
-
478
+
479
- break;
479
+ break;
480
-
480
+
481
- }
481
+ }
482
-
482
+
483
- r = p;
483
+ r = p;
484
484
 
485
485
  p = p->next;
486
486
 

1

追加

2017/05/22 23:16

投稿

A.Ichi
A.Ichi

スコア4070

test CHANGED
@@ -317,3 +317,207 @@
317
317
 
318
318
 
319
319
  ```
320
+
321
+
322
+
323
+ ポインタの連結をソート版も作成してみました。
324
+
325
+ ```c
326
+
327
+ #include<stdio.h>
328
+
329
+ #include<string.h>
330
+
331
+ #include<stdlib.h>
332
+
333
+
334
+
335
+ struct data{
336
+
337
+ char name[256];
338
+
339
+ char mail[256];
340
+
341
+ int group;
342
+
343
+ int ID;
344
+
345
+ struct data *next;
346
+
347
+ };
348
+
349
+
350
+
351
+ struct data* new_data(struct data* list, int n);
352
+
353
+ void list_output(struct data* p);
354
+
355
+
356
+
357
+ int main(void){
358
+
359
+
360
+
361
+ struct data *list = NULL;
362
+
363
+ int i=1;
364
+
365
+ int n=1;
366
+
367
+
368
+
369
+ while(i){
370
+
371
+ list = new_data(list, n++);
372
+
373
+ scanf("%d",&i);
374
+
375
+ }
376
+
377
+
378
+
379
+ list_output(list);
380
+
381
+ return 0;
382
+
383
+ }
384
+
385
+
386
+
387
+ struct data* new_data(struct data* list, int n){
388
+
389
+ char check[256];
390
+
391
+ int a,b=0;
392
+
393
+
394
+
395
+ struct data* node = (struct data*)malloc(sizeof(struct data));
396
+
397
+ printf("データを入力してください。\n");
398
+
399
+ printf("name:");
400
+
401
+ scanf("%s",node->name);
402
+
403
+ printf("mail:");
404
+
405
+ scanf("%s",node->mail);
406
+
407
+
408
+
409
+ while(b!=1){
410
+
411
+ printf("group:");
412
+
413
+ scanf("%s",check);
414
+
415
+ a=0;
416
+
417
+ b=1;
418
+
419
+ while(check[a]!='\0'&& check[a] != '\n'){
420
+
421
+ if(check[a]<'0' || '9'<check[a]){
422
+
423
+ b=0;
424
+
425
+ printf("数字を入力してください。\n");break;
426
+
427
+ }
428
+
429
+ a++;
430
+
431
+ }
432
+
433
+ }
434
+
435
+ node->group = atoi(check);
436
+
437
+ node->ID = n;
438
+
439
+ node->next = NULL;
440
+
441
+
442
+
443
+ if(list == NULL){
444
+
445
+ list = node;
446
+
447
+ }
448
+
449
+ else{
450
+
451
+ struct data* p = list;
452
+
453
+ struct data* r = list;
454
+
455
+ while (1){
456
+
457
+ if(strcmp(p->name,node->name)>0){
458
+
459
+ node->next=p;
460
+
461
+ if(r==list){
462
+
463
+ list=node;
464
+
465
+ }else{
466
+
467
+ r->next=node;
468
+
469
+ }
470
+
471
+ break;
472
+
473
+ }
474
+
475
+ if (p->next==NULL){
476
+
477
+ p->next=node;
478
+
479
+ break;
480
+
481
+ }
482
+
483
+ r = p;
484
+
485
+ p = p->next;
486
+
487
+ }
488
+
489
+ }
490
+
491
+ return list;
492
+
493
+ }
494
+
495
+
496
+
497
+ void list_output(struct data *p){
498
+
499
+ int total=0;
500
+
501
+ while(p!=NULL){
502
+
503
+
504
+
505
+ printf("%s %s %d %d\n",p->name,p->mail,p->group,p->ID);
506
+
507
+ total++;
508
+
509
+ if(p->next == NULL)
510
+
511
+ break;
512
+
513
+ p=p->next;
514
+
515
+
516
+
517
+ }
518
+
519
+ printf("登録者数は%dです\n",total);
520
+
521
+ }
522
+
523
+ ```