Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

****Please help debug the C code below so that it compiles********** // - Implement each of the functions to create a working circular queue. //

****Please help debug the C code below so that it compiles**********

// - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. // - (You may consider using these printf statements to debug, but they should be removed from your final version) // ================================================== #ifndef MYQUEUE_H #define MYQUEUE_H

struct queue{ unsigned int back;

unsigned int front;

unsigned int size;

unsigned int capacity;

int* data;

};

typedef struct queue queue_t;

queue_t * create_queue(unsigned int capacity){

queue_t * myQueue=(queue_t *)malloc(sizeof(queue_t *));

myQueue->capacity=capacity;

myQueue->size=0;

myQueue->front=0;

myQueue->back=capacity-1;

myQueue->data=(int*)malloc(myQueue->capacity*(sizeof(int)));

return myQueue;

}

int queue_empty(queue_t * q){

return (q->size == 0);

}

int queue_full(queue_t * q){

return (q->size == q->capacity);

}

int queue_enqueue(queue_t * q, int item){

if (queue_full(queue_t * q) )

return -1;

q>back= (q->back + 1)%q->capacity;

q->data[q->back] = item;

q->size = q->size + 1;

printf("%d enqueued to queue ", item);

return 0;

}

int queue_dequeue(queue_t * q){

if (queue_empty(q))

exit(1);

int item = q->data[q->front];

q->front = (q->front + 1)%q->capacity;

q->size = q->size - 1;

return item;

}

unsigned int queue_size(queue_t * q){

if (queue_empty(q))

exit(1);

return q->size;

}

void free_queue(queue_t * q){

free(q->data);

free(q);

}

#endif

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions