#include<conio.h>
class queue
{
private:
int q[10],front,rear,n,x,i;
public:
queue()
{
cout<<"Enter the no.of elements:";
cin>>n;
front=0;
rear=0;
}
void add()
{
cout<<"Enter the element:";
cin>>x;
if(rear==n)
{
cout<<"Queue is full";
return;
}
else
{
rear=rear+1;
q[rear]=x;
}
}
int delet()
{
if(front==rear)
{
cout<<"Queue is empty";
return(0);
}
else
{
int y;
front=front+1;
y=q[front];
return(y);
}
}
void display()
{
for(i=front+1;i<=rear;i++)
{
cout<<q[i]<<”\t”;
}
}
};
void main()
{
clrscr();
int choice;
queue q;
do
{
cout<<"\n1.Add"<<endl;
cout<<"2.Delete"<<endl;
cout<<"3.Display"<<endl;
cout<<"4.Exit"<<endl;
cout<<"Enter the choice:";
cin>>choice;
if(choice==1)
{
q.add();
cout<<"The elements after addition are "<<endl;
q.display();
}
if(choice==2)
{
int p;
p=q.delet();
cout<<"The deleted element is:"<<p;
cout<<"\nThe element after deletion are "<<endl;
q.display();
}
if(choice==3)
{
cout<<"The queue elements are"<<endl;
q.display();
}
}while(choice!=4);
getch();
}
No comments:
Post a Comment