Department of Gompulerdcience Page No.
: 26
QUEUE IMPLEMENTATlON USING ARKAYS
og Am
mpprt ova io. Darta Input tream
elass eue
private t max Size
Private lovg ueue Aray,
prvate iettront;
private int rear
private temS
oublic quene Cint s)
.
maxSi z e = S;
q e Aray= ew
kovng EmaxSizel;
tront= O;
ear =
ltemS = 0
publie void lnsert long j
f (rea= maxsize
rear -1
g ue Avray C++ Teav
TSbakshniTOomen'sDegree College
Deparlment of Gompulerdcience Page No.: 27
nIt enms +t
publicong remove ()
temp 9ue Aray [front 4+
if(front == maxSize)
tront = 6
nItems
Teturn tem p
public void print
tor (int i=front, t<rear; t+)
system.out.printNCaué Avra y[il)
class aueue
pablie staie void main (stsing asgsL)
ueue eue(5)
int ch
VSLakshmi Oomen':Degree Colege
Deparlmenl of Compuler dcience Page No. : 23
Data Tnpat Stream in mew
ataTupct &tream (systein);
do
Sy6tem -out. pTint ln 1Tnsert \m ")
System. out. println C "a. Delete \n");
system. out.print Ln ("a. rint \n ");
system. out.print kn (Eter your ehoice "
ch=
teger. parse Tut (in.reod Line C);
Suoiteh Cch)
Case l syst eym.out. psintin ( "Entey amy elemet"
u t n eInteger. parse Lnt(in.readLie
s. inser (n);
break
Cose 2
6.remóve (
brea k
Cose 8 S S. psint();
rCak
whtle Cche+);
Catch CExc eption e
TUSBakshi Women'sDegree College
Department of Gompuler deience Page No.: 29
Output
tInsert
2. Delete
3. r i n t
Enter your choice
Enter amy elememt
2
w .-
. Inset
2.DeLete
3. P i n t
Entes you choice
Ente any element
Tnset
2. Delete
3 Psint
Enter youd chojce
USLakshmiComen'sDegree Gollege