#include<iostream>

#define MX5

using namespace std;
int queue[MX];
int front = -1,rear =-1;
void enque(int item)
{
if(rear==MX-1)
{
cout<<“Queue is Full\n”; } else if(front == -1 && rear==-1) { front++; rear++; queue[rear]=item; } else { rear++; queue[rear]=item; } } int deque() { if(front==-1 || front>rear)
{
return -1;
}
else {
int temp = queue[front];
front++;
return temp;
}
}
int main()
{
int ch;
cout<<“1.Enque into Queue\n”; cout<<“2.Deque into Queue\n”; cout<<“3.print the Queue\n”; cout<<“4.Exit the Queue\n”; do{ cout<<“enter the choice\n”; cin>>ch;
switch(ch)
{
case 1:
{
int item;
cout<<“Enter the item to insert\n”; cin>>item;
enque(item);
break;
}
case 2:
{
int data = deque();
if(data==-1)
{
cout<<“Queue is empty\n”;
}
else{
cout<<“popper item is”<<data<<“\n”;
}
break;
}
case 3:
{
if(front==-1||rear<front)
{
cout<<“Queue is empty\n”;
}
else{
for(int i=front;i<=rear;i++)
cout<<queue[i]<<” “;
cout<<“\n”;
}
break;
}
case 4:
{
return 0;
}
default:
{
cout<<“please enter a valid choice\n”;
break;
}
}
}while(ch!=4);
return 0;
}

By RRR

Leave a Reply

Your email address will not be published.