Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

DESCRIBE six government-sponsored benefits.

Answered: 1 week ago

Question

KEY QUESTION Refer to columns 1 and 6 in the table for question

Answered: 1 week ago