Header Ads

Implementation of Circular Queue using C++ | Insert Operation Delete Operation isFull isEmpty Operation using C++

 In This  Post Implementation of Circular Queue using C++ 

How to Insert Operation using C++ Circular Queue Data Structure 

How to Delete Operation using C++ Circular Queue Data Structure 

isFull isEmpty Operation using C++  Circular Queue Data Structure 


Program Source Code

#include<iostream>

#define Max 5

using namespace std;

class CrQueue{

private:

    int front,rear,CrQ[5];

public:

CrQueue(){

front = -1;

rear = -1;

}

void InsertQueue(int n){

if((front == 0 && rear == Max-1)||(front == rear+1)){

cout<<"Queue is OverFlowed"<<endl;

}

if(front == -1){

front = 0;

rear = 0;

}

else{

if(rear ==Max-1)

   rear = 0;

else

   rear = rear+1;

}

CrQ[rear] = n;

}

void DeleteQueue(){

if(front == -1){

cout<<"Queue is UnderFlowe"<<endl;

}

else{

cout<<"Value is Delete from Queue is "<<CrQ[front]<<endl;

if(front == rear){

  front = -1;

  rear = -1;

}   

else{

if(front == Max-1)

   front = 0;

else

   front = front + 1;

}

}

}

void display(){

if(front == -1){

cout<<"Queue is Empty"<<endl;

}

else   

for(int i = front; i<=rear; i++)

   cout<<CrQ[i]<<" ";

   cout<<endl;

}

};

main(){

CrQueue obj1;

int num,op;

char choice;

do{

system("cls");

cout<<"1. Insert value into Queue"<<endl;

cout<<"2. Delete Value from Queue"<<endl;

cout<<"3. Display Value of Queue"<<endl;

cout<<"---Enter Your Choice ---";

cin>>op;

switch(op){

case 1:

cout<<"Enter Value to insert Queue:";

cin>>num;

obj1.InsertQueue(num);

break;

case 2:

obj1.DeleteQueue();

break;

case 3:

obj1.display();

break;

default:

cout<<"You Enter Invalid Number:"<<endl;

}

cout<<"Do You Want to Continue [Yes / No ] ?";

cin>>choice;

}while(choice == 'Y'||choice == 'y');

}


Related Video





No comments

Powered by Blogger.