Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

image text in transcribed

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 val

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions