0% found this document useful (0 votes)
4 views2 pages

Circular Queue Implementation in C++

Uploaded by

3001YashKithe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Circular Queue Implementation in C++

Uploaded by

3001YashKithe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include<iostream>

using namespace std;


const int SIZE = 10;

class CircularQueue
{
int queue[SIZE];
int front,rear;

public:
CircularQueue()
{
front = -1;
rear = -1;
}

// Enqueue Operation
void enqueue(int value)
{
if((rear+1)%SIZE==front)
{
cout<<"Queue is Full. \n";
return;
}
if(front==-1)front=0;
rear=(rear+1)%SIZE;
queue[rear]=value;
cout<<"Inserted : "<<value<<endl;
}

// Dequeue Operation
void dequeue()
{
if(front==-1)
{
cout<<"Queue is Empty. \n";
return;
}
cout<<"Deleted : "<<queue[front]<<endl;
if(front==rear)
{
front=rear=-1; //Queue is now Empty
}
else
{
front=(front+1)%SIZE;
}
}

// Display Queue
void display()
{
if(front==-1)
{
cout<<"Queue is Empty. \n";
return;
}
cout<<"Queue : ";
int i=front;
while(true)
{
cout<<queue[i]<<" ";
if(i==rear)
break;
i=(i+1)%SIZE;
}
cout<<endl;
}
};

int main()
{
CircularQueue q;
int choice,value,count;

do
{
cout<<"-------------------------------------------";
cout<<"\nMenu :\[Link]\[Link]\[Link]\[Link]\n";
cout<<"---------------------\nEnter Choice : ";
cin>>choice;

switch(choice)
{
case 1:
cout<<"Enter number of Values to Insert : ";
cin>>count;
for(int i=0;i<count;i++)
{
cout<<"Enter Value "<<i+1<<" : ";
cin>>value;
[Link](value);
}
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
cout << "Exiting Program..." << endl;
break;
default :
cout<<"Invalid Choice ! Try again.\n";
break;
}
}
while(choice!=4);
return 0;
}

You might also like