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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning