L linkj New Member Sep 27, 2003 #1 typedef struct node { Itemtype item; struct node *next; } Node; typedef struct deqstruct{ Node *front; Node *back; int size; } *Deq; void initdeq(Deq *d) { (*d)->size = 0; (*d)->front = NULL; (*d)->back = NULL; } does the initialization looks right to u??? it is compiled, but it got segmentation fault (core dumped) when i run it. can any one tell me why??
typedef struct node { Itemtype item; struct node *next; } Node; typedef struct deqstruct{ Node *front; Node *back; int size; } *Deq; void initdeq(Deq *d) { (*d)->size = 0; (*d)->front = NULL; (*d)->back = NULL; } does the initialization looks right to u??? it is compiled, but it got segmentation fault (core dumped) when i run it. can any one tell me why??
Exo Active Member Sep 28, 2003 #2 initdeq should be void initdeq(Deq *d) { d->size = 0; d->front = NULL; d->back = NULL; }
E egh01 New Member Sep 28, 2003 #3 Why do you typedef/declare the the deqstructure as a pointer? (*Deq) When you do that you get an segmentation error when you assign size the way you do. Try with: typedef struct deqstruct{ ... } Deq;
Why do you typedef/declare the the deqstructure as a pointer? (*Deq) When you do that you get an segmentation error when you assign size the way you do. Try with: typedef struct deqstruct{ ... } Deq;
Exo Active Member Sep 28, 2003 #4 It could be he dynamically allocates memory for the structure (wich i assumed). If not, then you're right egh01.
It could be he dynamically allocates memory for the structure (wich i assumed). If not, then you're right egh01.