Question

Consider the following structure definitions and fill in the blanks for the dequeue function: typedef struct...

Consider the following structure definitions and fill in the blanks for the dequeue 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;};
/* removes and returns the item at the head of the queue q,
 * or NULL if q is empty. */
void *dequeue (queue_t *q) {
    if (q->head == NULL) {
        return NULL;
    }
    void *val = __________________________;
    node_t *p = __________________________;
    q->head = __________________________;
    free(p);
    if (q->head == NULL) {
        q->tail = NULL; 
    }

return val; }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I would like to suggest some errors in the code. First of all, the dequeue functions return type is void. Therefore, it cannot return val.

The answer:

void *val = q->head;

node_t *p = q->head;

q->head = q->head->next;

Add a comment
Know the answer?
Add Answer to:
Consider the following structure definitions and fill in the blanks for the dequeue function: typedef struct...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT