Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Systems Programming Consider the following structure definitions: typedef struct queue queue t; typedef struct node node_t; struct node [ node t *next; void *val; struct
Systems Programming
Consider the following structure definitions: typedef struct queue queue t; typedef struct node node_t; struct node [ node t *next; void *val; struct queue t node t *head; node_t *tail; For this problem you are to complete a handful of methods that implement a queue data structure The following program demonstrates their use: queue-t *q make-queue(); = enqueue(q, "supercali"); printf("%s", dequeue (q)); enqueue(q, "fragi"); enqueue(q, "listic"); enqueue(q, "expiali"); enqueue(q, "docious"); char *c = NULL while ((c - dequeue(q) ( ue printf ("%s", c); free(q); When run, the program's output is as follows supercalifragilisticexpialidocious Note that there are no memory leaks. Complete the implementations of make_queue, enqueue and dequeue on the followin /*allocates and returns an empty queue queue_t *make_queue ) I queue.t *qmalloc(sizeof( q->head = q->tail -NULL; return q; /*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; /*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-headNULL) return NULL; void *val node_t *p q->head = free(p); if (q->head-NULL) { q->tail - NULL; return valStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started