#include <iostream>
using namespace std;
class CircularQueue{
private:
int front;
int rear;
int arr[5];
int itemCount=0;
public:
CircularQueue(){
front=-1;
rear=-1;
for(int i=0;i < 5;i++)
arr[i]=0;
}
bool isempty(){
if(front==-1 && rear==-1) return true;
else return false;
}
bool isFull(){
if((rear+1)%5==front) return true;
else return false;
}
void enqueue(int value) {
if (isFull()) {
cout << "Queue is Full" << endl;
return;
} else if (isempty()) {
front = 0;
rear = 0;
} else {
rear = (rear + 1) % 5;
}
arr[rear] = value;
itemCount++;
}
int dequeue(){
int temp;
if(isempty()){
cout<<"Queue is empty"<< endl;
return 0;
}
else if(front==rear){
temp=arr[front];
arr[front]=0;
front=rear=-1;
itemCount--;
return temp;
} else{
temp=arr[front];
arr[front]=0;
front=(front+1)%5;
itemCount--;
return temp;
}
}
int count(){
return itemCount;
}
void display(){
cout<<"All values in the Queue are: "<<endl;
for(int i=0;i< 5;i++)
cout<<arr[i]<<" ";
}
};
int main(){
CircularQueue q;
int option, value;
do {
cout<<"What operation would you like to perform?"<<endl;
cout<<"1.Enqueue()"<<endl;
cout<<"2.Dequeue()"<<endl;
cout<<"3.isEmpty()"<<endl;
cout<<"4.isFull()"<<endl;
cout<<"5.count()"<<endl;
cout<<"6.display()"<<endl;
cout<<"7.clear screen"<<endl;
cout<<"Enter your choice (enter 0 for exit)"<<endl;
cin>>option;
switch (option) {
case 0:cout<<"Exit"<<endl;
break;
case 1:cout<<"Enqueue Operations"<<endl;;
cout<<"Enter the value:";
cin>>value;
q.enqueue(value);
break;
case 2:cout<<"Dequeued operation\nDequeued value: " << q.dequeue() << endl;
break;
case 3:
if (q.isempty()) cout<<"Queue is empty."<<endl;
else cout<<"Queue is not empty."<<endl;
break;
case 4:
if(q.isFull()) cout<<"Queue is full"<<endl;
else cout<<"Queue is not full"<<endl;
break;
case 5:
cout<<"Count Operations\nNumber of elements in the queue: "<<q.count()<<endl;
break;
case 6:
cout<<"Queue items: ";
q.display();
break;
default:
cout<<"Invalid option! Please try again."<<endl;
}
} while (option!=0);
return 0;
}