質問編集履歴
2
文字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,35 +14,35 @@
|
|
14
14
|
|
15
15
|
```lang-言語名
|
16
16
|
|
17
|
-
void enq(struct
|
17
|
+
void enq(struct LIST **head, struct cell **tail, int val,int n){
|
18
18
|
|
19
|
-
struct
|
19
|
+
struct LIST *p;
|
20
20
|
|
21
21
|
if(n==1){
|
22
22
|
|
23
|
-
p = (struct
|
23
|
+
p = (struct LIST *)malloc(sizeof(struct LIST);
|
24
24
|
|
25
|
-
|
25
|
+
p->num = val;
|
26
26
|
|
27
27
|
//ここでセグメンテーション違反になってしまいます。
|
28
28
|
|
29
|
-
|
29
|
+
p->next = NULL;
|
30
30
|
|
31
|
-
head = tail = p;
|
31
|
+
*head = *tail = p;
|
32
32
|
|
33
33
|
}
|
34
34
|
|
35
35
|
else{
|
36
36
|
|
37
|
-
p = (struct
|
37
|
+
p = (struct LIST *malloc(sizeof(struct LIST));
|
38
38
|
|
39
|
-
|
39
|
+
p->num = val;
|
40
40
|
|
41
|
-
|
41
|
+
p->next = NULL;
|
42
42
|
|
43
|
-
(*tail)->next =
|
43
|
+
(*tail)->next = p;
|
44
44
|
|
45
|
-
tail = p;
|
45
|
+
*tail = p;
|
46
46
|
|
47
47
|
}
|
48
48
|
|
@@ -50,15 +50,15 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
int deq(struct
|
53
|
+
int deq(struct LSIT **head){
|
54
54
|
|
55
55
|
int deqdata;
|
56
56
|
|
57
|
-
struct
|
57
|
+
struct LSIT *p;
|
58
58
|
|
59
59
|
deqdata = (*head)->num;
|
60
60
|
|
61
|
-
p = head;//警告
|
61
|
+
p = *head;//警告
|
62
62
|
|
63
63
|
head = &(*head)->next;
|
64
64
|
|
@@ -72,9 +72,9 @@
|
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
-
void free_queue(struct
|
75
|
+
void free_queue(struct LIST **head){
|
76
76
|
|
77
|
-
struct
|
77
|
+
struct LIST *p;
|
78
78
|
|
79
79
|
if(head!=NULL)
|
80
80
|
|
@@ -93,3 +93,7 @@
|
|
93
93
|
In function ‘free_queue’:
|
94
94
|
|
95
95
|
警告: ‘p’ may be used uninitialized in this function
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
ちゃんとコンパイルできたけどdeqを行ったら強制終了されました。
|
1
改善したい点
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
キューを使ってenqueue,dequeueするプログラムをポインタのポインタを引数に持つ関数で作りたいです。
|
4
4
|
|
5
5
|
deq操作を行う関数とキューの中をカラにする関数で警告がでます。無視して実行するとセグメンテーション違反になります。どう改良すればいいでしょうか。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
訂正
|
10
|
+
|
11
|
+
|
6
12
|
|
7
13
|
|
8
14
|
|
@@ -17,6 +23,8 @@
|
|
17
23
|
p = (struct cell **)malloc(sizeof(struct cell *));
|
18
24
|
|
19
25
|
(*p)->num = val;
|
26
|
+
|
27
|
+
//ここでセグメンテーション違反になってしまいます。
|
20
28
|
|
21
29
|
(*p)->next = NULL;
|
22
30
|
|
@@ -46,7 +54,7 @@
|
|
46
54
|
|
47
55
|
int deqdata;
|
48
56
|
|
49
|
-
struct cel **p;
|
57
|
+
struct cell **p;
|
50
58
|
|
51
59
|
deqdata = (*head)->num;
|
52
60
|
|
@@ -66,7 +74,7 @@
|
|
66
74
|
|
67
75
|
void free_queue(struct cell **head){
|
68
76
|
|
69
|
-
struct cel **p;
|
77
|
+
struct cell **p;
|
70
78
|
|
71
79
|
if(head!=NULL)
|
72
80
|
|