Question: Could you fix it so queue index goes back to location 0 when it reaches max #include using namespace std; #define MAX 50 int arr[MAX];

Could you fix it so queue index goes back to location 0 when it reaches max

#include

using namespace std;

#define MAX 50

int arr[MAX];

int rear = - 1;

int front = - 1;

void ADD();

void SHOW();

void DELETE();

void COUNT();

int main()

{

int choice;

while (1)

{

cout<<"1.Insert element to queue ";

cout<<"2.Delete element from queue ";

cout<<"3.Display all elements of queue ";

cout<<"4.Count number of elements in queue ";

cout<<"5.Quit ";

cout<<"Enter your choice : ";

cin>>choice;

switch (choice)

{

case 1:

ADD();

break;

case 2:

DELETE();

break;

case 3:

SHOW();

break;

case 4:

COUNT();

break;

case 5:

exit(1);

default:

printf("Wrong choice ");

}

}

return 0;

}

void ADD()

{

int item;

if (rear == MAX - 1)

cout<<"Queue Overflow ";

else

{

if (front == - 1)

front = 0;

cout<<"Inset the element in queue : ";

cin>>item;

rear = rear + 1;

arr[rear] = item;

}

}

void DELETE()

{

if (front == - 1 || front > rear)

{

cout<<"Queue Underflow ";

return ;

}

else

{

cout<<"Element deleted from queue is : "<

front = front + 1;

}

}

void SHOW()

{

int i;

if (front == - 1)

cout<<"Queue is empty ";

else

{

cout<<"Queue is : ";

for (i = front; i <= rear; i++)

cout<

cout<<" ";

}

}

void COUNT()

{

int i,c;

for (i = front; i <= rear; i++)

c=c+1;

cout<<"Number of element in the queue is "<

}

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!