In: Computer Science
Consider the following structure definitions and fill in the blanks for the enqueue function:
typedef struct queue queue_t; typedef struct node node_t;
struct node { node_t *next; void *val; };
struct queue { node_t *head; node_t *tail;};
/* add val at the tail of the queue q */
void enqueue (queue_t *q, void *val) { if (q->head == NULL) {
_______________ = _______________ = malloc(sizeof(_______________));
_______________ = NULL; } else {
_______________ = _______________ = malloc(sizeof(_______________));
_______________ = NULL; }
q->tail->val = val; }
typedef struct queue queue_t; typedef struct node node_t;
struct node { node_t *next; void *val; };
struct queue { node_t *head; node_t *tail;};
/* add val at the tail of the queue q */
void enqueue (queue_t *q, void *val) { if (q->head == NULL) {
q->head = q->tail = malloc(sizeof(struct node));
q->head->next = NULL; } else {
q->tail = q->tail->next = malloc(sizeof(struct node));
q->tail->next = NULL; }
q->tail->val = val; }