回答編集履歴
1
insert の変更を追記
test
CHANGED
@@ -113,3 +113,49 @@
|
|
113
113
|
}
|
114
114
|
|
115
115
|
```
|
116
|
+
|
117
|
+
**追記**
|
118
|
+
|
119
|
+
```C
|
120
|
+
|
121
|
+
void insert(struct node *p, char x) {
|
122
|
+
|
123
|
+
while (p->next != NULL) p = p->next; // ★ 追加: 最後を見つける
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
struct node *n;
|
128
|
+
|
129
|
+
n = (struct node*)malloc(sizeof(struct node));
|
130
|
+
|
131
|
+
n->element = x;
|
132
|
+
|
133
|
+
n->next = p->next;
|
134
|
+
|
135
|
+
p->next = n;
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
void printlist(struct node *p) {
|
142
|
+
|
143
|
+
if(p->next == NULL) {
|
144
|
+
|
145
|
+
putchar('\n');
|
146
|
+
|
147
|
+
}else {
|
148
|
+
|
149
|
+
p = p->next;
|
150
|
+
|
151
|
+
putchar(p->element);
|
152
|
+
|
153
|
+
printlist(p);
|
154
|
+
|
155
|
+
// putchar(p->element); // ★ 削除
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
```
|