a C++ program explains the concept of queue and deletes the itemsfrom queue i am
ID: 3609406 • Letter: A
Question
a C++ program explains the concept of queue and deletes the itemsfrom queue i am having the code just need some correction out ofthat please help me the code is as followsvoid main()
{
clrscr();
int Q[9],front=0,rear=0,item,lb=1,ub=9,choice=0;
cout<<"Delete Item From Queue: ";
cin>>item;
if(front==0 && rear==0)
{
cout<<"Underflow Error";
exit(0);
}
if(front==rear)
{
rear=0;
front=0;
}
else
{
if(front==ub)
{
front=lb;
}
else
{
front=front+1;
}
}
for(int i=0;i<=front+1;i++)
{
cout<<"Value at poistion"<<i+1;
cout<<" of queue is"<<Q[i+1]<<endl;
}
Explanation / Answer
Dear,//C++ Program to implement theQueue #include <iostream.h>
#include <conio.h>
int rear,front=0,q[5],ele;
void menu()
{
cout<<"QUEUEOPERATIONS"<<endl<<"-----------------"<<endl<<"1.Insert"<<endl<<"2.Delete"<<endl<<"3.Display"<<endl<<"4.Exit"<<endl;
}
void insert()
{
if(rear==5)
cout<<"Queue is full"<<endl;
else
{
cout<<"Insert an element"<<endl;
cin>>ele;
q[rear]=ele;
rear++;
}
cout<<endl;
}
void delet()
{
if(front==rear)
cout<<"Queue is empty"<<endl;
else
{
cout<<"Deleted element is:"<<q[front]<<endl;
front++;
}
cout<<endl;
}
void display()
{
if(front==rear)
cout<<"Queue is empty"<<endl;
else
{
cout<<"The elements in the queue are:"<<endl;
for(int i=front;i<rear;i++)
cout<<q[i]<<" ";
}
cout<<endl;
}
void main()
{
int ch;
clrscr();
do
{
menu();
cout<<"Enter your choice"<<endl;
cin>>ch;
switch(ch)
{
case 1:insert();break;
case 2:delet();break;
case 3:display();break;
case 4:break;
}
}while(ch!=4);
} I hope this is helpful foru...........
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.