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
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