Question: Please comment this code. queueADT.c #include #include #include sqjuggler.h struct queue_type{ int contents[QUEUE_SIZE]; int last,first,length; }; static void terminate(const char *message) { printf(%s ,message); exit(EXIT_FAILURE);

Please comment this code.

queueADT.c

#include #include #include "sqjuggler.h"

struct queue_type{ int contents[QUEUE_SIZE]; int last,first,length; };

static void terminate(const char *message) { printf("%s ",message); exit(EXIT_FAILURE); }

queue create(void) { Queue q=malloc(sizeof(struct queue_type)); if(q==NULL) terminate("Error in create: queue could not be created."); q->last=0; q->first=0; q->length=0; return q; }

void destroy(Queue q) { make_empty(q);

free(q);

}

void make_empty(Queue q) { q->last=0; q->first=0; q->length=0; }

bool is_empty(Queue q) { return q->length==0; }

bool is_full(Queue q) { return q->length==QUEUE_SIZE; }

void insert(Queue q,int i) { if(is_full(q)) terminate("Error in insert: queue is full.");

q->contents[q->last++]=i; if(q->length==0) q->first=q->last; q->length=q->length+1; if(q->last>=QUEUE_SIZE) q->last=0; }

Item remove_que(Queue q) { int element=0;

if(is_empty(q))

terminate("Error in removal: queue is empty.");

element=q->contents[(q->first)-1]; q->length=q->length-1; q->first++;

if(q->first>q->last||q->first>QUEUE_SIZE) q->first=0; return element; }

int first(Queue q) { return q->contents[(q->first)-1]; }

int last(Queue q) { return q->contents[(q->last)-1]; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!