回答編集履歴
1
用意してたソースの供養
test
CHANGED
@@ -3,3 +3,105 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
そう思うのでしたらやってみたらどうでしょうか
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
----
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
供養
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```c
|
20
|
+
|
21
|
+
#include <stdio.h>
|
22
|
+
|
23
|
+
#include <stdlib.h>
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
struct list;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
typedef struct list {
|
32
|
+
|
33
|
+
int data;
|
34
|
+
|
35
|
+
struct list *next;
|
36
|
+
|
37
|
+
} list;
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
list* list_alloc(int data) {
|
42
|
+
|
43
|
+
list *p = malloc(sizeof(list));
|
44
|
+
|
45
|
+
p->data = data;
|
46
|
+
|
47
|
+
p->next = NULL;
|
48
|
+
|
49
|
+
printf("new list[%p] => %d, %p\n", p, data, &(p->next));
|
50
|
+
|
51
|
+
return p;
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
void insert2(list ** head_p, int data) {
|
58
|
+
|
59
|
+
puts("-------------");
|
60
|
+
|
61
|
+
list * new = list_alloc(data);
|
62
|
+
|
63
|
+
list **p = head_p;
|
64
|
+
|
65
|
+
printf("head_p = %p, *head_p = %p\n", head_p, *head_p);
|
66
|
+
|
67
|
+
while( お && か ) {
|
68
|
+
|
69
|
+
printf("p = %p, *p = %p, ", p, *p);
|
70
|
+
|
71
|
+
printf("next_p = %p, *next_p = %p\n", き, *き);
|
72
|
+
|
73
|
+
// もしもタイムアウトになったならば以下のコメントアウトを外す
|
74
|
+
|
75
|
+
// return;
|
76
|
+
|
77
|
+
p = き; // 次のnextメンバーを指す
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
new->next = *p;
|
82
|
+
|
83
|
+
*p = new;
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
int main() {
|
88
|
+
|
89
|
+
list *head = NULL;
|
90
|
+
|
91
|
+
insert2(&head,100);
|
92
|
+
|
93
|
+
insert2(&head,50);
|
94
|
+
|
95
|
+
insert2(&head,20);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
お、か、きを埋めて[wandbox](https://wandbox.org)なり[paiza.io](https://paiza.io/ja)なり
|
104
|
+
|
105
|
+
で実行してみてはどうでしょう。
|
106
|
+
|
107
|
+
(一番いいのはMSVCでデバッグ実行ですが)
|