1) Change it to an implementation in a circular fashion. (2) Change it to handle the exceptions. (3) Change the main() function, such that it a. receives integers from the standard I/O and perform enqueue() operations until the queue is full. b. performs one more enqueue() operation to show your program able to handle fullQueue exception. c. prints out the size and all the elements in the queue to show the queue is full with totally 10 integers in it. d. performs dequeue() operations until the queue is empty. e. performs one more dequeue() operation to show your program is able to handle emptyQueue exception. f. Implement a function deleteElement(Q, x) that deletes an element (integer) x from queue Q if x is in Q. g. Call function deleteElement(Q, x) and show that it works correctly. please check

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The following C program is an implementation of Queue using an array.

 

#include <stdio.h>

#include <stdlib.h>

#define size 11

 

void enqueue(int *q,int *tail, int element);

int dequeue(int *q,int *head);

int full(int tail,const int size);

int empty(int head,int tail);

void init(int *head, int *tail);

void init(int *head, int *tail)

{*head = *tail = 0;}

 

void enqueue(int *q,int *tail, int element)

{ q[(*tail)++] = element;}

 

int dequeue(int *q,int *head)

{ return q[(*head)++];}

 

int full(int tail,const int size)

{return tail == size ? 1 : 0;}

 

int empty(int head, int tail)

{return head == tail ? 1 : 0;}

}

 

void main(){

int head,tail,element;

int queue[size];

 

init(&head,&tail);

// enqueue elements

while(full(tail,size) != 1){

element = rand();

printf("enqueue %d\n",element);

enqueue(queue,&tail,element);

printf("head=%d,tail=%d\n",head,tail);

}

printf("queue is full\n");

 

// dequeue elements from

while(!empty(head,tail)){

element = dequeue(queue,&head);

printf("dequeue element %d \n",element);

}

printf("queue is empty\n");

}

 

(1) Change it to an implementation in a circular fashion.
(2) Change it to handle the exceptions.
(3) Change the main() function, such that it
a. receives integers from the standard I/O and perform enqueue() operations until the queue is full.
b. performs one more enqueue() operation to show your program able to handle fullQueue exception.
c. prints out the size and all the elements in the queue to show the queue is full with totally 10 integers in it.
d. performs dequeue() operations until the queue is empty.
e. performs one more dequeue() operation to show your program is able to handle emptyQueue exception.
f. Implement a function deleteElement(Q, x) that deletes an element (integer) x from queue Q if x is in Q.
g. Call function deleteElement(Q, x) and show that it works correctly.

please check

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Randomized Select Algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education