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

Circular Queue Using Array

The document describes an implementation of a circular queue using arrays in C language. It includes functions to insert an element, delete an element and display all elements of the queue. It uses concepts like front and rear pointers to keep track of the first and last elements in the queue.

Uploaded by

satish kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Circular Queue Using Array

The document describes an implementation of a circular queue using arrays in C language. It includes functions to insert an element, delete an element and display all elements of the queue. It uses concepts like front and rear pointers to keep track of the first and last elements in the queue.

Uploaded by

satish kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Pr

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;

You might also like