Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
32 views7 pages

BFHFHB

Uploaded by

saee7390
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)
32 views7 pages

BFHFHB

Uploaded by

saee7390
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/ 7

#Programme:-

#include<stdio.h>
#include<conio.h>
#define max 4
int
q[10],front=0,rear
=-1;
void main()
{
int ch;
void insert();
void delet();
void display();

clrscr();

printf("\nCircular
Queue
operations\n");

printf("1.Insert\n2
.Delete\n3.Displa
y\n4.Exit\n");
while(1)
{
printf("Enter your
choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: insert();
break;
case 2: delet();
break;
case 3:display();
break;
case 4:exit();

default:printf("Inv
alid option\n");
}
}
}

void insert()
{
int x;
if((front==0&&rea
r==max-
1)||(front>0&&re
ar==front-1))

printf("Queue is
overflow\n");
else
{
printf("Enter
element to be
insert:");
scanf("%d",&x);
if(rear==max-
1&&front>0)
{
rear=0;
q[rear]=x;
}
else
{

if((front==0&&rea
r==-
1)||(rear!=front-
1))
q[++rear]=x;
}
}
}
void delet()
{
int a;

if((front==0)&&(re
ar==-1))
{
printf("Queue is
underflow\n");
getch();
exit();
}
if(front==rear)
{
a=q[front];
rear=-1;

front=0;
}
else
if(front==max-1)
{
a=q[front];
front=0;
} else
a=q[front++];
printf("Deleted
element
is:%d\n",a);
}

void display()
{
int i,j;

if(front==0&&rear
==-1)
{
printf("Queue is
underflow\n");
getch();
exit();
}
if(front>rear)
{

for(i=0;i<=rear;i++
)
{

printf("\t%d",q[i])
;
{

for(j=front;j<=max
-1;j++)

printf("\t%d",q[j])
;
printf("\nrear is
at %d\n",q[rear]);
printf("\nfront is
at
%d\n",q[front]);
}
}
}
else
{

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

printf("\t%d",q[i])
; }
printf("\nrear is at
%d\n",q[rear]);
printf("\nfront is
at
%d\n",q[front]);
}
printf("\n");
getch();
}

You might also like