質問編集履歴
1
コードを挿入しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,726 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
#define _CRT_SECURE_NO_WARNINGS
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
#include <stdio.h>
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
#include <stdlib.h>
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
#include <string.h>
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
/*データ*/
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
typedef struct {
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
int num; //学籍番号下三桁
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
char name[16]; //氏名
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
}data_t;
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
/*ノード*/
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
typedef struct node {
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
data_t data; //データ
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
struct node* nextnode; //後ろのノードへのポインタ
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
}node_t;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
/*関数プロトタイプ宣言*/
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
node_t* make_node(data_t, node_t*);
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
node_t* add_data(node_t*);
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
node_t* remove_data(node_t*);
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
void search_data(node_t*);
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
void show_data(node_t*);
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
void release(node_t*);
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
int main(void)
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
int menu;
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
node_t* node = NULL;
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
do {
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
puts("");
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
puts("***メニューの選択***");
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
puts(" 1.データの表示");
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
puts(" 2.データの追加");
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
puts(" 3.データの検索");
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
puts(" 4.データの削除");
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
puts(" 5.終了");
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
printf("メニューの選択:");
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
scanf("%d", &menu);
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
puts("");
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
switch (menu)
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
case 1:show_data(node); break;
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
case 2: node = add_data(node); break;
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
case 3: search_data(node); break;
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
case 4:node = remove_data(node); break;
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
case 5: puts("プログラムを終了"); break;
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
default:puts("番号を再入力"); break;
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
} while (menu != 5);
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
release(node);
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
// system("pause"); コメント
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
return 0;
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
/*新規ノードの作成*/
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
node_t* make_node(data_t data, node_t* nextnode)
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
{
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
node_t* p;
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
p = malloc(sizeof(node_t));
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
if (p == NULL) {
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
puts("領域確保に失敗");
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
return NULL;
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
else {
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
p->data = data;
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
p->nextnode = nextnode;
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
return p;
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
/*データの追加*/
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
node_t* add_data(node_t* node)
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
{
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
data_t data;
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
node_t* p = node;
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
puts("***追加するデータの入力***");
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
printf("学籍番号の下二桁の番号:");
|
336
|
+
|
337
|
+
scanf("%d", &data.num);
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
printf("氏名:");
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
scanf("%s", data.name);
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
while (node != NULL && p->nextnode != NULL) {
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
p = p->nextnode;
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
if (node == NULL) {
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
node = make_node(data, NULL);
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
else {
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
p->nextnode = make_node(data, NULL);
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
return node;
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
/*データの表示*/
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
void show_data(node_t* node)
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
{
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
node_t* p = node;
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
if (p == NULL) {
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
puts("データがありません。データを追加してください。");
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
return;
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
while (p != NULL) {
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
printf("番号%*s氏名\n", 6, "");
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
printf("%2d %10s\n", (p->data).num, (p->data).name);
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
p = p->nextnode;
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
}
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
/*データの削除*/
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
node_t* remove_data(node_t* node)
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
{
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
int num;
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
node_t* head = node;
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
node_t* pre = NULL;
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
if (node == NULL) {
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
puts("データは見つかりませんでした。");
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
return NULL;
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
}
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
puts("***データの削除***");
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
printf("番号の入力:");
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
scanf("%d", &num);
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
while (node->nextnode != NULL) {
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
if ((node->data).num == num) {
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
if (pre == NULL) {
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
return node->nextnode;
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
}
|
536
|
+
|
537
|
+
else {
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
pre->nextnode = node->nextnode;
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
free(node);
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
return head;
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
}
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
}
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
pre = node;
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
node = node->nextnode;
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
}
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
puts("データは見つかりませんでした。");
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
return head;
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
}
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
/*データの検索*/
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
void search_data(node_t* node)
|
594
|
+
|
595
|
+
|
596
|
+
|
597
|
+
{
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
int num;
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
node_t* p = node;
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
puts("***データの検索***");
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
printf("番号の入力:");
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
scanf("%d", &num);
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
if (node == NULL) {
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
puts("データは見つかりませんでした");
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
return;
|
638
|
+
|
639
|
+
|
640
|
+
|
641
|
+
}
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
while (p->nextnode != NULL) {
|
646
|
+
|
647
|
+
|
648
|
+
|
649
|
+
if ((p->data).num == num) {
|
650
|
+
|
651
|
+
|
652
|
+
|
653
|
+
puts("---データを発見---");
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
printf("氏名:%s\n", (p->data).name);
|
658
|
+
|
659
|
+
|
660
|
+
|
661
|
+
return;
|
662
|
+
|
663
|
+
|
664
|
+
|
665
|
+
}
|
666
|
+
|
667
|
+
|
668
|
+
|
669
|
+
p = p->nextnode;
|
670
|
+
|
671
|
+
|
672
|
+
|
673
|
+
}
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
puts("データは見つかりませんでした");
|
678
|
+
|
679
|
+
|
680
|
+
|
681
|
+
}
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
|
688
|
+
|
689
|
+
/*データの後処理*/
|
690
|
+
|
691
|
+
|
692
|
+
|
693
|
+
void release(node_t* node)
|
694
|
+
|
695
|
+
|
696
|
+
|
697
|
+
{
|
698
|
+
|
699
|
+
|
700
|
+
|
701
|
+
node_t* p;
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
if (node == NULL) return;
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
p = node;
|
710
|
+
|
711
|
+
|
712
|
+
|
713
|
+
release(p->nextnode);
|
714
|
+
|
715
|
+
|
716
|
+
|
717
|
+
free(p);
|
718
|
+
|
719
|
+
|
720
|
+
|
721
|
+
}
|
722
|
+
|
1
|
-
出席簿
|
723
|
+
```出席簿
|
2
724
|
|
3
725
|
|
4
726
|
|