Question: I need help on this project is for Data Structure. Thanks The output here is the queue.h HEre is test.c Programming Project 3: Circular Queue

I need help on this project is for Data Structure. Thanks

I need help on this project is for Data Structure. Thanks The

output here is the queue.h HEre is test.c Programming Project 3: Circular

The output

Queue Programming Project 3: Circular Queue Submit Assignment Due Apr 2 by

here is the queue.h

11:59pm Points 100 Submitting a file upload File Types c Available until

HEre is test.c

Apr 2 at 11:59pm Project Description and Requirements Dynamic memory is physically

allocated in a linear manner, but can logically be used as if

Programming Project 3: Circular Queue Programming Project 3: Circular Queue Submit Assignment Due Apr 2 by 11:59pm Points 100 Submitting a file upload File Types c Available until Apr 2 at 11:59pm Project Description and Requirements Dynamic memory is physically allocated in a linear manner, but can logically be used as if it were connected end-to-end. In this way, a linearly allocated array can be used in a circular manner. The following structured data type defines the data structure of a queue with an internal circular buffer: typedef struct Queue { int front; //the array index of the front element int rear; //the array index of the rear element int size; //the number of elements in the queue int capacity; //the capacity of the queue int *array; //the pointer to the circular buffer } Queue; Whenever a circular queue is empty, both the front index and rear index should be holding an invalid array index -1, and the size should be 0. The queue capacity will remain the same throughout the queue's entire life. This project involves a header file, queue.h, which contains the definition for the Queue structured data type, as well as functional prototypes for all the required functions in this project. You should #include this header file from your queue.c source file, like so: #include "queue.h" = 3 Starting from an empty queue, front = -1, rear = -1, size = 0, capacity The queue has: Adding 8 to the rear, front = 0, rear = 0, size = 1, capacity = 3 The queue has: 8 = 3 Adding 61 to the rear, front = 0, rear = 1, size = 2, capacity The queue has: 8 61 rear = 2, size = 3, capacity = 3 Adding 16 to the rear, front = The queue has: 8 61 16 2, size = 3, capacity = 3 Adding 34 to the rear, front = 0, rear = The queue has: 8 61 16 rear = 2, size = Adding 58 to the rear, front = The queue has: 8 61 16 3, capacity = 3 Making the queue empty, front = -1, rear = -1, size = 0, capacity = 3 The queue has: rear = 0, size = 1, capacity = 3 Adding 42 to the rear, front = The queue has: 42 = 3 Adding 53 to the rear, front = 0, rear = 1, size = 2, capacity The queue has: 42 53 Adding 4 to the rear, front = 0, rear = 2, size = 3, capacity = 3 The queue has: 42 53 4 rear = 2, size = Adding 36 to the rear, front = The queue has: 42 53 4 3, capacity = 3 Adding 49 to the rear, front = 0, rear = 2, size = 3, capacity = 3 The queue has: 42 53 4 Removing 42 from the front, front = 1, rear = 2, size = 2, capacity = 3 The queue has: 53 4 Removing 53 from the front, front = 2, rear = 2, size = 1, capacity = 3 The queue has: 4 Adding 68 to the rear, front = 2, rear = 0, size = 2, capacity = 3 The queue has: 4 68 Adding 43 to the rear, front = 2, rear = 1, size = 3, capacity = 3 The queue has: 4 68 43 2, rear = 1, size = 3, capacity = 3 Adding 36 to the rear, front = The queue has: 4 68 43 #ifndef QUEUE_H #define QUEUE_H typedef struct Queue { int front; //the array index of the front element int rear; //the array index of the rear element int size; //the number of elements in the queue int capacity; //the capacity of the queue int *array; //the pointer to the circular buffer } Queue; //create an empty queue with an array of the desired capacity Queue *createQueue (int capacity); 1 /destroy the queue Queue *destroyQueue (Queue *9); //return 1 if the queue is empty, o otherwise int isEmpty(Queue *); //make the queue empty void makeEmpty(Queue *q); //return 1 if the queue is full, o otherwise int isFull(Queue *9); 1/add a new element to the rear of the queue void enqueue (Queue *q, int data); //remove and return the front element from the queue int dequeue (Queue *9); 1/print the queue elements void printQueue (Queue *9); #endif #include #include #include "queue.h" int main() { Queue *q; int i, temp; q = createQueue (3); printf(" Starting from an empty queue, front = %d, rear = %d, size = %d, capacity = %d ", q->front, q->rear, q->size, q->capacity); printf("The queue has: "); printQueue (9); printf(" "); srand(time(NULL)); for (i = 0; i front, q->rear, 9->size, q->capacity); printf("The queue has: "); printQueue (9); printf(" "); if (i == 4) { makeEmpty(); printf(" Making the queue empty, front = %d, rear = %d, size = %d, capacity = %d ", q->front, 9->rear, q->size, q->capacity); printf("The queue has: "); printQueue (9); printf(" "); } } = %d, size = %d, for (i = 0; i front, q->rear, q->size); printf("The queue has: "); printQueue (9); printf(" "); } for (i = 0; i front, q->rear, q->size, q->capacity); printf("The queue has: "); printQueue (9); printf(" "); } }

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!