Circular Queue Using Array
Circular Queue Using Array
ogr
am -
Arr
ayi
mpl
ement
ati
onofci
rcul
arqueue.
.
#i
ncl
ude<st
dio.
h>
#def
inemax6
i
ntqueue[
max]
;//ar
raydecl
arat
ion
i
ntf
ront
=-1
;
i
ntr
ear
=-1
;
/
/funct
iont
oinser
tanel
ementi
naci
rcul
arqueue
voi
denqueue(
intel
ement
)
i
f(
front
==-
1&&r
ear
==-
1)/
/condi
ti
ont
ocheckqueuei
sempt
y
f
ront
=0;
r
ear
=0;
queue[
rear
]=el
ement
;
el
sei
f(
(rear
+1)
%max==f
ront
)//condi
ti
ont
ocheckqueuei
sful
l
pr
int
f("
Queuei
sover
fl
ow.
.
");
el
se
{
r
ear
=(r
ear
+1)
%max; /
/reari
sincr
ement
ed
queue[
rear
]=el
ement
; /
/assi
gni
ngaval
uet
othequeueatt
he
r
earposi
ti
on.
/
/funct
iont
odel
etet
heel
ementf
rom t
hequeue
i
ntdequeue(
)
i
f(
(fr
ont
==-
1)&&(
rear
==-
1))/
/condi
ti
ont
ocheckqueuei
sempt
y
pr
int
f("
\nQueuei
sunder
fl
ow.
.
");
el
sei
f(
front
==r
ear
)
pr
int
f("
\nThedequeuedel
ementi
s%d"
,queue[
front
]);
f
ront
=-1
;
r
ear
=-1
;
el
se
{
pr
int
f("
\nThedequeuedel
ementi
s%d"
,queue[
front
]);
f
ront
=(f
ront
+1)
%max;
/
/funct
iont
odi
spl
ayt
heel
ement
sofaqueue
voi
ddi
spl
ay(
)
i
nti
=fr
ont
;
i
f(
front
==-
1&&r
ear
==-
1)
pr
int
f("
\nQueuei
sempt
y..
")
;
el
se
pr
int
f("
\nEl
ement
sinaQueuear
e:"
);
whi
l
e(i
<=r
ear
)
pr
int
f("
%d,
",queue[
i]
);
i
=(i
+1)
%max;
}
i
ntmai
n()
i
ntchoi
ce=1
,x;/
/var
iabl
esdecl
arat
ion
whi
l
e(choi
ce<4&&choi
ce!
=0) /
/whi
l
eloop
pr
int
f("
\nPr
ess1
:Inser
tanel
ement
");
pr
int
f("
\nPr
ess2:Del
eteanel
ement
");
pr
int
f("
\nPr
ess3:Di
spl
ayt
heel
ement
");
pr
int
f("
\nEnt
eryourchoi
ce"
);
scanf
("%d"
,&choi
ce)
;
swi
tch(
choi
ce)
case1
:
pr
int
f("
Ent
ert
heel
ementwhi
chi
stobei
nser
ted"
);
scanf
("%d"
,&x)
;
enqueue(
x);
br
eak;
case2:
dequeue(
);
br
eak;
case3:
di
spl
ay(
);
}
}
r
etur
n0;