# include<iostream>
# define MAX 5
using namespace std;
int qu[MAX];
int r = -1;
int f = -1;
void insert();
void del();
void disply();
int main()
{
int choice;
do
{
cout<<"1.Insert\n";
cout<<"2.Delete\n";
cout<<"3.Display\n";
cout<<"4.Quit\n";
cout<<"Enter your choice : ";
cin>>choice;
switch(choice)
{
case 1 :insert();break;
case 2 :del();break;
case 3:display();break;
case 4:exit(1);
default:
cout<<"Wrong choice\n";
}
}while(choice!=4);
return 0;
}
void insert()
{
int added_item;
if (r==MAX-1)
cout<<"Queue Overflow\n";
else
{
if (f==-1)
f=0;
cout<<"Input the element for adding in queue : ";
cin>>added_item;
r=r+1;
qu[r] = added_item ;
}
}
void del()
{
if (f == -1 || f > r)
{
cout<<Queue Underflow\n";
return ;
}
else
{
cout<<"Element deleted from queue is :"
cout<<"\n"<<qu[f];
f=f+1;
}
}
void display()
{
int i;
if (f ==-1 )
cout<<Queue is empty\n";
else
{
cout<<"Queue is :\n";
for(i=f;i<= r;i++)
cout<<qu[i]<<"\n";
}
}
No comments:
Post a Comment