#include <iostream>
#define MAX 5
using namespace std;
int array[MAX];
int front=-1,rear=-1,count=0;
void enqueue() ///enqueue element from this function
{
if(MAX==count) ///if the array is full
{
cout<<"Your Queue is Full"<<endl;
}
else
{
int data;
cout<<"Data: ";
cin>>data;
if(front==-1) ///for the 1st input
{
front++;
rear++;
}
else
{
rear = (rear+1)%MAX; /// increment rear by add 1 and then Mood the rear with Max
}
array[rear]=data; ///save data
count++;///increment count
}
}
void dequeue()
{
if(count==0) ///if the array is empty
{
cout<<"The Queue is Empty"<<endl<<endl;
return;
}
cout<<" Data : "<<array[front]<<" Eliminated"<<endl;
front = (front+1)%MAX; ///increment front value and mood the value by MAX
count--;///decrement count
}
void display()
{
int c,i;
if(count==0)///if the array is empty
{
cout<<"The Queue is Empty"<<endl<<endl;
return;
}
cout<<"Your Queue: ";
for(i=front,c=1; c<=count; i = (i+1)%MAX,c++) ///compare c with count and increase the i value and mood it by MAX
{
cout<<array[i]<<" ";
}
cout<<endl;
}
void menu()
{
int n;
while(1)
{
cout<<"Press 1 For EnqueuePress 2 For DequeuePress 3 For Display QueuePress 0 For Exit";
cin>>n;
if(n==1)
{
enqueue();
}
else if(n==2)
{
dequeue();
}
else if(n==3)
{
display();
}
else if(n==0)
{
return;
}
}
}
int main()
{
menu();
return 0;
}
Output
Press 1 For Enqueue
Press 2 For Dequeue
Press 3 For Display Queue
Press 0 For Exit
1
Data: 1
Press 1 For Enqueue
Press 2 For Dequeue
Press 3 For Display Queue
Press 0 For Exit
1
Data: 2
Press 1 For Enqueue
Press 2 For Dequeue
Press 3 For Display Queue
Press 0 For Exit
3
Your Queue: 1 2
Press 1 For Enqueue
Press 2 For Dequeue
Press 3 For Display Queue
Press 0 For Exit
2
Data : 1 Eliminated
Press 1 For Enqueue
Press 2 For Dequeue
Press 3 For Display Queue
Press 0 For Exit
3
Your Queue: 2
Press 1 For Enqueue
Press 2 For Dequeue
Press 3 For Display Queue
Press 0 For Exit
1
Data: 5
Press 1 For Enqueue
Press 2 For Dequeue
Press 3 For Display Queue
Press 0 For Exit
3
Your Queue: 2 5
Press 1 For Enqueue
Press 2 For Dequeue
Press 3 For Display Queue
Press 0 For Exit
0
2 previous comments
72 hazard of BCSM compared with that in ER negative patients, whereas ER positive patients older than 40 yr had a substantially higher 10 yr BCSS around 93 95, with comparable HRs with ER negative patients at 5 10 yr Table 3 and Fig <a href=http://cialiss.cfd>buy cialis online prescription</a>
Qyfwdp Lightrelated diseases and disorders of pigmentation. [url=https://oscialipop.com]is generic cialis available[/url] <a href=https://oscialipop.com>Cialis</a> Addiction is the physical and psychological dependence on and craving for a drug and the presence of clearly unpleasant effects when that drug or other agent is withdrawn. See Figure https://oscialipop.com - best cialis online foro comprar viagra por internet