Circular Queue using Array in CPP

Circular queue implementation in C++ using single dimensional array. Right now we are using Dev C++ IDE to run this program, you can use any compatible IDE to run this circular queue program.

//program to implement circular queue using array
// name			: rakesh kumar
// date 		:
#include
#include
#include
using namespace std;
const int MAX = 5;
  class cqueue
	  {
		   int a[MAX],front,rear;
		public :
		   cqueue()
		   {
			 front=rear=-1;
		   }
		   void insert(int );
		   int deletion();
		   void display();
	  };

  void cqueue :: insert(int val)
	  {
		 if((front==0 && rear==MAX-1) || (rear+1==front))
			  {
			  	cout<<" Circular Queue is Full"; getch();
			  }
		 else
		 {
		   if(rear==MAX-1)
			  rear=0;
		   else
			 rear++;
		   a[rear]=val;
		 }
		 if(front==-1)
		   front=0;
	  }
	  
  int cqueue :: deletion()
	  {
		 int value;
		 if(front==-1)
			{
				cout<<"Circular Queue is Empty"; getch();
			}
		 else
		 {
			value=a[front];
			if(front==rear)
			   front=rear=-1;
			else
			{
			   if(front==MAX-1)
				  front=0;
			   else
				  front++;
			}
		 }
		 return value;
	  }
	  void cqueue :: display()
	  {
		  int i;
		  if(front==-1)
			 {
			 	cout<<"Circular Queue is Empty"; getch();
			 }
			 
		  else
		  {
			 if(rear < front)
			 {
				for(i=front;i<=MAX-1;i++)
				   cout< : ";
		   cin>>ch;
		   switch(ch)
		   {
			   case 1 : cout<<"Enter Element to Insert ?";
						cin>>val;
						c1.insert(val);
						break;
			   case 2 : val=c1.deletion();
						cout<<"Deleted Element :"<

Download File :

One thought on “Circular Queue using Array in CPP

Leave a Reply