0% found this document useful (0 votes)
34 views

Circular Queue Using Array

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

Circular Queue Using Array

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

Program – Circular Queue Using Array

#include<iostream.h>
#include<conio.h>
#include<process.h>
int q[5];
const int max=5;
int front=-1,rear=-1;
int item;
void insert();
void dele();
void displayq();
void main()
{
clrscr();
int choice;
do
{
cout<<"\nCircular Queue Menu\n";
cout<<"1. Insert\n";
cout<<"2. Delete\n";
cout<<"3. Display\n";
cout<<"4. Exit\n";
cout<<" Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1: insert();
break;
case 2: dele();
break;
case 3: displayq();
break;
case 4: exit(0);
default: cout<<"\nPlease enter a valid choice! ";
}
}while(choice!=4);
getch();
}
void insert()
{
if((front==0)&&(rear==max-1)||(front==rear+1))
{
cout<<"\nOverflow!";
getch();
return;
}
cout<<"\nEnter the item to be inserted: ";
cin>>item;
if(front==-1)
{
front=0;
rear=0;
}
else if(rear==max-1)
rear=0;
else
rear=rear+1;
q[rear]=item;
}
void dele()
{
if(front==-1)
{
cout<<"\nUnderflow! Queue empty";
getch();
return;
}
cout<<"\nThe deleted value is "<<q[front]<<"\n";
if(front==rear)
{
front=-1;
rear=-1;
}
else if(front==max-1)
front=0;
else
front=front+1;
}
void displayq()
{
if(front==-1)
{
cout<<"\nEmpty Queue!";
getch();
return;
}
cout<<"\nThe queue is:\n";
if(front<=rear)
{
for(int i=front;i<=rear;i++)
cout<<q[i]<<"\t";
}
else
{
for(int i=front;i<max;i++)
cout<<q[i]<<"\t";
for(i=0;i<=rear;i++)
cout<<q[i]<<"\t";
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy