質問編集履歴
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,98 @@
|
|
1
|
+
```#include <stdio.h>
|
2
|
+
|
3
|
+
#include <stdlib.h>
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
typedef int elementtype;
|
10
|
+
|
11
|
+
struct node {
|
12
|
+
|
13
|
+
elementtype element;
|
14
|
+
|
15
|
+
struct node* next;
|
16
|
+
|
17
|
+
};
|
18
|
+
|
19
|
+
typedef struct node* list;
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
list cons(elementtype e, list l) {
|
24
|
+
|
25
|
+
list n;
|
26
|
+
|
27
|
+
n = (list)malloc(sizeof(struct node));
|
28
|
+
|
29
|
+
n->element = e;
|
30
|
+
|
31
|
+
n->next =l;
|
32
|
+
|
33
|
+
return n;
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
int length(list l) {
|
38
|
+
|
39
|
+
int c = 0;
|
40
|
+
|
41
|
+
while(l!=NULL){
|
42
|
+
|
43
|
+
c++;
|
44
|
+
|
45
|
+
l = l->next;
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
return c;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
void print_int_list(list l) {
|
54
|
+
|
55
|
+
while (l != NULL) {
|
56
|
+
|
57
|
+
printf("[%d]", l->element);
|
58
|
+
|
59
|
+
l = l->next;
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
int main() {
|
68
|
+
|
69
|
+
int i;
|
70
|
+
|
71
|
+
wchar_t buf[128];
|
72
|
+
|
73
|
+
list l = NULL;
|
74
|
+
|
75
|
+
while(fgetws(buf, sizeof(buf), stdin) !=NULL) {
|
76
|
+
|
77
|
+
sscanf(buf, "%d", &i);
|
78
|
+
|
79
|
+
l = cons(i, l);
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
printf("length=%d\n", length(l));
|
86
|
+
|
87
|
+
print_int_list(l);
|
88
|
+
|
89
|
+
return 0;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
コード
|
94
|
+
|
1
|
-
### 前提・実現したいこと
|
95
|
+
```### 前提・実現したいこと
|
2
96
|
|
3
97
|
|
4
98
|
|