#include<iostream>
#include<cstdlib>
#define max 10
using namespace std;
class queues
{
int que[max];
int front,rear;
public:
queues()
{
front=-1;
rear=-1;
}
void insert(int);
void del();
void display();
};
void queues::insert(int ele)
{
if(rear==max)
cout<<"\nQueue overflow";
else if(rear==-1)
{
que[++rear]=ele;
front++;
}
else
que[++rear]=ele;
}
void queues::del()
{
if(front==rear)
cout<<"\nQueue is empty";
else
front++;
}
void queues::display()
{
for(int i=front;i<=rear;i++)
cout<<que[i]<<"\t";
}
int main()
{
queues ob;
int op,ele;
while(1)
{
cout<<"\nMenu is ";
cout<<"\n1.Insert \n2.Delete \n3.Display \n4.Exit";
cout<<"\nYour choice is ";
cin>>op;
switch(op)
{
case 1:
{
cout<<"\nEnter element to be inserted";
cin>>ele;
ob.insert(ele);
}
break;
case 2:
ob.del();
break;
case 3:
ob.display();
break;
case 4:
exit(1);
}
}
}
No comments:
Post a Comment