キューを使ってenqueue,dequeueするプログラムをポインタのポインタを引数に持つ関数で作りたいです。
deq操作を行う関数とキューの中をカラにする関数で警告がでます。無視して実行するとセグメンテーション違反になります。どう改良すればいいでしょうか。
訂正
lang
1void enq(struct LIST **head, struct cell **tail, int val,int n){ 2 struct LIST *p; 3 if(n==1){ 4 p = (struct LIST *)malloc(sizeof(struct LIST); 5 p->num = val; 6//ここでセグメンテーション違反になってしまいます。 7 p->next = NULL; 8 *head = *tail = p; 9 } 10 else{ 11 p = (struct LIST *malloc(sizeof(struct LIST)); 12 p->num = val; 13 p->next = NULL; 14 (*tail)->next = p; 15 *tail = p; 16 } 17} 18 19int deq(struct LSIT **head){ 20 int deqdata; 21 struct LSIT *p; 22 deqdata = (*head)->num; 23 p = *head;//警告 24 head = &(*head)->next; 25 free(p); 26 return deqdata; 27} 28 29 30void free_queue(struct LIST **head){ 31 struct LIST *p; 32if(head!=NULL) 33 free(p);//警告 34}
コンパイル
In function ‘deq’:
警告: assignment from incompatible pointer type
In function ‘free_queue’:
警告: ‘p’ may be used uninitialized in this function
ちゃんとコンパイルできたけどdeqを行ったら強制終了されました。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。