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

Circular Queue

Circular queue

Uploaded by

satish kumar
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)
16 views

Circular Queue

Circular queue

Uploaded by

satish kumar
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/ 5

#i

ncl
ude<st
dio.
h>

#def
ineMAX5

i
ntcqueue_
arr
[MAX]
;

i
ntf
ront=-
1;

i
ntr
ear=-
1;

voi
dinser
t(i
nti
tem)

i
f(
(f
ront==0&&r
ear==MAX-
1)|
|(f
ront==r
ear
+1)
)

pr
int
f("
QueueOver
fl
own"
);

r
etur
n;

i
f(
front==-
1)

f
ront=0;

r
ear=0;

el
se

i
f(
rear==MAX-
1)

r
ear=0;

el
se

r
ear=r
ear
+1;

}
cqueue_
arr
[rear
]=i
tem;

voi
ddel
eti
on(
)

i
f(
front==-
1)

pr
int
f("
QueueUnder
fl
own"
);

r
etur
n;

pr
int
f("
Elementdel
etedf
romqueuei
s:%dn"
,cqueue_
arr
[fr
ont
]);

i
f(
front==r
ear
)

f
ront=-
1;

r
ear
=-1
;

el
se

i
f(
front==MAX-
1)

f
ront=0;

el
se

f
ront=f
ront
+1;

voi
ddi
spl
ay(
)

{
i
ntf
ront
_pos=f
ront
,r
ear
_pos=r
ear
;

i
f(
front==-
1)

pr
int
f("
Queuei
sempt
yn"
);

r
etur
n;

pr
int
f("
Queueel
ement
s:n"
);

i
f(f
ront
_pos<=r
ear
_pos)

whi
l
e(f
ront
_pos<=r
ear
_pos)

pr
int
f("
%d"
,cqueue_
arr
[fr
ont
_pos]
);

f
ront
_pos++;

el
se

whi
l
e(f
ront
_pos<=MAX-
1)

pr
int
f("
%d"
,cqueue_
arr
[fr
ont
_pos]
)

f
ront
_pos++;

f
ront
_pos=0;

whi
l
e(f
ront
_pos<=r
ear
_pos)

pr
int
f("
%d"
,cqueue_
arr
[fr
ont
_pos]
);

f
ront
_pos++;
}

pr
int
f("
n")
;

i
ntmai
n()

i
ntchoi
ce,
i
tem;

do

pr
int
f("
1.
Inser
tn"
);

pr
int
f("
2.Del
eten"
);

pr
int
f("
3.Di
spl
ayn"
);

pr
int
f("
4.Qui
tn"
);

pr
int
f("
Ent
eryourchoi
ce:
");

scanf
("
%d"
,&choi
ce)
;

swi
tch(
choi
ce)

case1:

pr
int
f("
Inputt
heel
ementf
ori
nser
ti
oni
nqueue:
");

scanf
("
%d"
,&i
tem)
;

i
nser
t(i
tem)
;

br
eak;

case2:

del
eti
on(
);

br
eak;
case3:

di
spl
ay(
);

br
eak;

case4:

br
eak;

def
aul
t:

pr
int
f("
Wrongchoi
cen"
);

}
whi
l
e(choi
ce!
=4)
;

r
etur
n0;

You might also like