Vous êtes sur la page 1sur 52

EX.

NO:5 ARRAY IMPLEMENTATION OF LIST ADT


DATE :
AIM:
To Write a C++ Program for arra im!"eme#tatio# of "i$t ADT.
AL%ORIT&M:
Ste!': Create #o(e$ fir$t)"a$t)#e*t)!re+ a#( ,-r t.e# $et t.e +a"-e a$ N/LL.
Ste! 0: Rea( t.e "i$t o!eratio# t!e.
$te! 1: If o!eratio# t!e i$ ,reate t.e# !ro,e$$ t.e fo""o2i#g $te!$.
'. A""o,ate memor for #o(e ,-r.
0. Rea( (ata i# ,-r3$ (ata area.
1. A$$ig# ,-r #o(e a$ N/LL.
4. A$$ig# fir$t5"a$t5,-r.
Ste! 4: If o!eratio# t!e i$ I#$ert t.e# !ro,e$$ t.e fo""o2i#g $te!$.
'. A""o,ate memor for #o(e ,-r.
0. Rea( (ata i# ,-r3$ (ata area.
1. Rea( t.e !o$itio# t.e Data to 6e i#$ert.
4. A+ai"a6i"it of t.e !o$itio# i$ tr-e t.e# a$$i#g ,-r3$ #o(e a$ fir$t a#( fir$t5,-r.
5. If a+ai"a6i"it of !o$itio# i$ fa"$e t.e# (o fo""o2i#g $te!$.
'. A$$ig# #e*t a$ ,-r a#( ,o-#t a$ 7ero.
0. Re!eat t.e fo""o2i#g $te!$ -#ti" ,o-#t "e$$ t.a# !o$tio#.
' .A$$ig# !re+ a$ #e*t
0. Ne*t a$ !re+ of #o(e.
1. A(( ,o-#t 6 o#e.
4. If !re+ a$ N/LL t.e# (i$!"a t.e me$$age IN8ALID POSITION.
5. If !re+ #ot 9-a" to N/LL t.e# (o t.e fo""o2i#g $te!$.
'. A$$ig# ,-r3$ #o(e a$ !re+3$ #o(e.
0. A$$ig# !re+3$ #o(e a$ ,-r.
Ste!5: If o!eratio# t!e i$ (e"ete t.e# (o t.e fo""o2i#g $te!$.
'. Rea( t.e !o$itio# .
0. C.e,: "i$t i$ Em!t .If it i$ tr-e (i$!"a t.e me$$age Li$t em!t.
1. If !o$itio# i$ fir$t.
'. A$$ig# ,-r a$ fir$t.
0. A$$ig# Fir$t a$ fir$t of #o(e.
1. Rea""o,ate t.e ,-r from memor.
4. If !o$itio# i$ "a$t.
'. Mo+e t.e ,-rre#t #o(e to !re+.
0. ,-r3$ #o(e a$ N-"".
1. Rea""o,ate t.e La$t from memor.
4. A$$ig# "a$t a$ ,-r.
5. If !o$itio# i$ e#ter Me(iate.
'. Mo+e t.e ,-r to re9-ire( !o$tio#.
0. Mo+e t.e Pre+io-$ to ,-r3$ !re+io-$ !o$itio#
1. Mo+e t.e Ne*t to ,-r3$ Ne*t !o$itio#.
4. No2 A$$ig# !re+io-$ of #o(e a$ #e*t.
5. Rea""o,ate t.e ,-r from memor.
$te! ;: If o!eratio# i$ tra+er$e.
'. A$$ig# ,-rre#t a$ fir$t.
0. Re!eat t.e fo""o2i#g $te!$ -#ti"" ,-r 6e,ome$ N/LL.
PRO%RAM
<i#,"-(e=io$tream..>
<i#,"-(e=,o#io..>
<i#,"-(e=!ro,e$$..>
+oi( ,reate?@A
+oi( i#$ert?@A
+oi( (e"etio#?@A
+oi( $ear,.?@A
+oi( (i$!"a?@A
i#t a)6B0CD)#)()e)f)iA
+oi( mai#?@
E
i#t ,A
,.ar g533A
,"r$,r?@A
(o
E
,o-t==FG# Mai# Me#-FA
,o-t==FG# '.Create G# 0.De"ete G# 1.Sear,. G# 4.i#$ert G# 5.Di$!"a G# ;.E*itFA
,o-t==FG# e#ter o-r ,.oi,eG#FA
,i#>>,A
$2it,.?,@
E
,a$e ': ,reate?@A 6rea:A
,a$e 0: (e"etio#?@A 6rea:A
,a$e 1: $ear,.?@A 6rea:A
,a$e 4: i#$ert?@A 6rea:A
,a$e 5: (i$!"a?@A 6rea:A
,a$e ;: e*it?C@A 6rea:A
(efa-"t:
,o-t==FT.e gi+e# #-m6er i$ #ot 6et2ee# 'H5G#FA
I
,o-t==FG#Do - 2a#t to ,o#ti#-e G#FA
,i#>>gA
,"r$,r?@A
I
2.i"e?g5533JJ g553Y3@A
get,.?@A
I
+oi( ,reate?@
E
,o-t==FG# E#ter t.e #-m6erG#FA
,i#>>#A
for?i5CAi=#Ai++@
E
,i#>>6BiDA
II
+oi( (e"etio#?@
E
,o-t==FE#ter t.e "imit - 2a#t to (e"ete G#FA
,i#>>(A
for?i5CAi=#Ai++@
E
if?6BiD55(@
E
6BiD5CA
III
+oi( $ear,.?@
E
,o-t==FE#ter t.e "imit G#FA
,i#>>eA
for?i5CAi=#Ai++@
E
if?6BiD55e@
E
,o-t==F8a"-e fo-#( t.e !o$itio#G#F==6BiDA
III
+oi( i#$ert?@
E
,o-t==Fe#ter .o2 ma# #-m6er - 2a#t to i#$ert G#FA
,i#>>fA
for?i5CAi=fAi++@
E
,i#>>6B#++DA
II
+oi( (i$!"a?@
E
,o-t==FG#G#G#FA
for?i5CAi=#Ai++@
E
,o-t==FG#G#G#F==6BiDA
I I
O-t!-t
Mai# Me#-
'.Create
0.De"ete
1.Sear,.
4.I#$ert
5.Di$!"a
;.E*it
E#ter o-r ,.oi,e
'
E#ter t.e #-m6er
0
1
4
Do - 2a#t to ,o#ti#-e
#
Re$-"t:
T.-$) t.e arra im!"eme#tatio# of "i$t ADT !rogram .a$ 6ee# 2ritte# a#( e*e,-te(
$-,,e$$f-"".
EX.NO:; Li#:e( "i$t im!"eme#tatio# of Li$t ADT
DATE :
AIM:
To Write a C++ Program for "i#:e( "i$t im!"eme#tatio# of "i$t ADT.
A"gorit.m:
Ste!': Create #o(e$ fir$t)"a$t)#e*t)!re+ a#( ,-r t.e# $et t.e +a"-e a$ N/LL.
Ste! 0: Rea( t.e "i$t o!eratio# t!e.
$te! 1: If o!eratio# t!e i$ ,reate t.e# !ro,e$$ t.e fo""o2i#g $te!$.
'. A""o,ate memor for #o(e ,-r.
0. Rea( (ata i# ,-r3$ (ata area.
1. A$$ig# ,-r "i#: a$ N/LL.
4. A$$ig# fir$t5"a$t5,-r.
Ste! 4: If o!eratio# t!e i$ I#$ert t.e# !ro,e$$ t.e fo""o2i#g $te!$.
'. A""o,ate memor for #o(e ,-r.
0. Rea( (ata i# ,-r3$ (ata area.
1. Rea( t.e !o$itio# t.e Data to 6e i#$erti#g.
4. A+ai"a6i"it of t.e !o$itio# i$ tr-e t.e# a$$ig# ,-r3$ "i#: a$ fir$t a#( fir$t5,-r.
5. If a+ai"a6i"it of !o$itio# i$ fa"$e t.e# (o fo""o2i#g $te!$.
'. A$$ig# #e*t a$ ,-r a#( ,o-#t a$ 7ero.
0. Re!eat t.e fo""o2i#g $te!$ -#ti" ,o-#t "e$$ t.a# !o$itio#.
' .A$$ig# !re+ a$ #e*t
0. Ne*t a$ !re+ of "i#:.
1. A(( ,o-#t 6 o#e.
4. If !re+ a$ N/LL t.e# (i$!"a t.e me$$age IN8ALID POSITION.
5. If !re+ #ot 9-a" to N/LL t.e# (o t.e fo""o2i#g $te!$.
'. A$$ig# ,-r3$ "i#: a$ !re+3$ "i#:.
0. A$$ig# !re+3$ "i#: a$ ,-r.
Ste!5: If o!eratio# t!e i$ (e"ete t.e# (o t.e fo""o2i#g $te!$.
'. Rea( t.e !o$itio# .
0. C.e,: "i$t i$ Em!t .If it i$ tr-e (i$!"a t.e me$$age Li$t em!t.
1. If !o$itio# i$ fir$t.
'. A$$ig# ,-r a$ fir$t.
0. A$$ig# Fir$t a$ fir$t of "i#:.
1. Rea""o,ate t.e ,-r from memor.
4. If !o$itio# i$ "a$t.
'. Mo+e t.e ,-rre#t #o(e to !re+.
0. ,-r3$ "i#: a$ N-"".
1. Rea""o,ate t.e La$t from memor.
4. A$$ig# "a$t a$ ,-r.
5. If !o$itio# i$ e#ter Me(iate.
'. Mo+e t.e ,-r to re9-ire( !o$itio#.
0. Mo+e t.e Pre+io-$ to ,-r3$ !re+io-$ !o$itio#
1. Mo+e t.e Ne*t to ,-r3$ Ne*t !o$itio#.
4. No2 a$$ig# !re+io-$ of "i#: a$ #e*t.
5. Rea""o,ate t.e ,-r from memor.
$te! ;: If o!eratio# i$ tra+er$e.
'. A$$ig# ,-rre#t a$ fir$t.
0. Re!eat t.e fo""o2i#g $te!$ -#ti" ,-r 6e,ome$ N/LL.
Program
<i#,"-(e=io$tream..>
<i#,"-(e=,o#io..>
<i#,"-(e=$t("i6..>
,"a$$ "i$t
E
$tr-,t #o(e
E
i#t (ataA
#o(e K"i#:A
IK!A
!-6"i,:
+oi( i#$"a$t?i#t@A
+oi( i#$6eg?i#t@A
+oi( i#$#e*t?i#t)i#t@A
+oi( (e"e"eme#t?i#t@A
+oi( (e"6eg?@A
+oi( (e""a$t?@A
+oi( (i$!?@A
i#t $ee:?i#t@A
"i$t?@E!5N/LLAI
L"i$t?@A
IA
+oi( "i$t::i#$"a$t?i#t *@
E
#o(e K9)KtA
if?!55N/LL@
E
!5#e2 #o(eA
!H>(ata5*A
!H>"i#:5N/LLA
I
e"$e
E
95!A
2.i"e?9H>"i#:M5N/LL@
959H>"i#:A
t5#e2 #o(eA
tH>(ata5*A
tH>"i#:5N/LLA
9H>"i#:5tA
I
,o-t==FG#G#I#$erte( $-,,e$$f-"" at t.e e#(..FA
(i$!?@A
I
+oi( "i$t:: i#$6eg?i#t *@
E
#o(e K9A
95!A
!5#e2 #o(eA
!H>(ata5*A
!H>"i#:59A
,o-t==FG#G#I#$erte( $-,,e$$f-"" at t.e 6egi#i#g..FA
(i$!?@A
I
+oi( "i$t::(e"e"eme#t?i#t *@
E
#o(e K9)KrA
95!A
if?9H>(ata55*@
E
!59H>"i#:A
(e"ete 9A
ret-r#A
I
r59A
2.i"e?9M5N/LL@
E
if?9H>(ata55*@
E
rH>"i#:59H>"i#:A
(e"ete 9A
ret-r#A
I
r59A
959H>"i#:A
I
,o-t==FG#G#E"eme#t o- e#tere( F==*==F i$ #ot fo-#(..FA
I
+oi( "i$t:: (e"6eg?@
E
,o-t==FG#G#T.e "i$t 6efore (e"etio#:FA
(i$!?@A
#o(e K9A
95!A
if?955N/LL@
E
,o-t==FG#G#No (ata i$ !re$e#t..FA
ret-r#A
I
!59H>"i#:A
(e"ete 9A
ret-r#A
I
+oi( "i$t:: (e""a$t?@
E
,o-t==FG#G#T.e "i$t 6efore (e"etio#:FA
(i$!?@A
#o(e K9)KtA
95!A
if?955N/LL@
E
,o-t==FG#G#T.ere i$ #o (ata i# t.e "i$t..FA
ret-r#A
I
if?9H>"i#:55N/LL@
E
!59H>"i#:A
(e"ete 9A
ret-r#A
I
2.i"e?9H>"i#:H>"i#:M5N/LL@
959H>"i#:A
9H>"i#:5N/LLA
ret-r#A
I
"i$t::L"i$t?@
E
#o(e K9A
if?!55N/LL@ ret-r#A
2.i"e?!M5N/LL@
E
95!H>"i#:A
(e"ete !A
!59A
I
I
+oi( "i$t::(i$!?@
E
#o(e K9A
95!A
if?955N/LL@
E
,o-t==FG#G#No (ata i$ i# t.e "i$t..FA
ret-r#A
I
,o-t==FG#G#T.e item$ !re$e#t i# t.e "i$t are G#FA
2.i"e?9M5N/LL@
E
,o-t==9H>(ata==FG#FA
959H>"i#:A
I
I
+oi( "i$t :: i#$#e*t?i#t +a"-e)i#t !o$itio#@
E
#o(e Ktem!)Ktem!'A
tem!5!A
if?tem!'55N/LL@
E
tem!'5 #e2 #o(eA
tem!'H>(ata5+a"-eA
tem!'H>"i#:5N/LLA
!5tem!'A
ret-r#A
I
for?i#t i5CA??i=!o$itio#@NN?tem!H>"i#:M5N/LL@@ Ai++@
E
if?i55?!o$itio#H'@@
E
tem!'5 #e2 #o(eA
tem!'H>(ata5 +a"-eA
tem!'H>"i#:5tem!H>"i#:A
tem!H>"i#:5tem!'A
I
tem!5tem!H>"i#:A
I
,o-t==FG#G#I#$erte( $-,,e$$f-"" at F==!o$itio#A
(i$!?@A
I
i#t "i$t::$ee:?i#t +a"-e@
E
#o(e Ktem!A
tem!5!A
i#t !o$itio#5CA
2.i"e?tem!M5N/LL@
E
if?tem!H>(ata55+a"-e@
ret-r# !o$itio#+'A
e"$e
E
tem!5tem!H>"i#:A
!o$itio#5!o$itio#+'A
I
I
,o-t==FG#G#E"eme#t F==+a"-e==F #ot fo-#(FA
ret-r# CA
I
+oi( mai#?@
E
"i$t "A
i#t ,.)+)!)!$A
(o
E
,"r$,r?@A
,o-t==FG#G#O!eratio#$ o# Li$t..FA
,o-t==FG#G#'.I#$ertio#G#0.De"etio#G#1.Di$!"aG#4.See:G#5.E*itFA
,o-t==FG#G#E#ter -r O!tio# :FA
,i#>>,.A
$2it,.?,.@
E
,a$e ':
,"r$,r?@A
,o-t==FINSERTIONFA
,o-t==FG#G#'.I#$ertio# at 6egi#i#gG#0.I#$ertio# at t.e e#(FA
,o-t==FG#1.I#$ertio# 6et2ee# t2o No(e$FA
,o-t==FG#G#E#ter -r ,.oi,e:FA
,i#>>!$A
,o-t==FE#ter t.e +a"-e to i#$ert:FA
,i#>>+A
$2it,.?!$@
E
,a$e ':
".i#$6eg?+@A
6rea:A
,a$e 0:
".i#$"a$t?+@A
6rea:A
,a$e 1:
,o-t==FG#E#ter t.e !o$itio# to i#$ert t.e +a"-e:FA
,i#>>!A
".i#$#e*t?+)!@A
6rea:A
(efa-"t:
,o-t==FG#T.e ,.oi,e i$ i#+a"i(FA
ret-r#A
I
6rea:A
,a$e 0:
,"r$,r?@A
,o-t==FG#'.De"ete t.e fir$t e"eme#tG#0.De"ete t.e "a$t e"eme#tFA
,o-t==FG#1.E#ter t.e e"eme#t to (e"ete from t.e "i$tFA
,o-t==FG#G#E#ter -r ,.oi,e:FA
,i#>>!$A
$2it,.?!$@
E
,a$e ':
".(e"6eg?@A
,o-t==FG#T.e "i$t after (e"etio#:FA
".(i$!?@A
6rea:A
,a$e 0:
".(e""a$t?@A
,o-t==FG#T.e "i$t after (e"etio#:FA
".(i$!?@A
6rea:A
,a$e 1:
".(i$!?@A
,o-t==FG#E#ter t.e e"eme#t to (e"ete : FA
,i#>>+A
".(e"e"eme#t?+@A
,o-t==FG#T.e "i$t after (e"etio#:FA
".(i$!?@A
6rea:A
(efa-"t:
,o-t==FG#T.e o!tio# i$ i#+a"i(...FA
6rea:A
I
6rea:A
,a$e 1:
,"r$,r?@A
".(i$!?@A
6rea:A
,a$e 4:
,"r$,r?@A
".(i$!?@A
,o-t==FG#E#ter t.e e"eme#t to $ear,.:FA
,i#>>+A
,o-t==FG#T.e !o$itio# of t.e e"eme#t F== +==F i$ F==".$ee:?+@A
get,.?@A
6rea:A
,a$e 5:
e*it?'@A
(efa-"t:
,o-t==FG#T.e o!tio# i$ i#+a"i(...FA
ret-r#A
I
get,.?@A
I2.i"e?,.M55@A
get,.?@A
ret-r#A
I
O-t!-t:
Si#g" Li#:e( Li$t
'.Create
0.I#$ert
1.De"ete
4.E*it
E#ter Yo-r C.oi,e : '
E#ter T.e Data: 'C
'C
'.Create
0.I#$ert
1.De"ete
4.E*it
E#ter Yo-r C.oi,e : 0
E#ter T.e Data: 1C
E#ter T.e Po$itio#: '
1C
'C
'.Create
0.I#$ert
1.De"ete
4.E*it

E#ter Yo-r C.oi,e : 1
E#ter T.e Po$itio# : 0
Li$t I$ Em!t
Re$-"t:
T.-$) t.e "i#:e( "i$t im!"eme#tatio# of "i$t ADT for $i#g" "i#:e( "i$t !rogram .a$ 6ee#
2ritte# a#( e*e,-te( $-,,e$$f-"".
EX.NO:O C-r$or im!"eme#tatio# of Li$t ADT
DATE :
AIM:
To Write a C++ Program for C-r$or im!"eme#tatio# of "i$t ADT.
A"gorit.m:
Ste!': Create #o(e$ fir$t)"a$t)#e*t)!re+ a#( ,-r t.e# $et t.e +a"-e a$ N/LL.
Ste! 0: Rea( t.e "i$t o!eratio# t!e.
$te! 1: If o!eratio# t!e i$ ,reate t.e# !ro,e$$ t.e fo""o2i#g $te!$.
'. A""o,ate memor for #o(e ,-r.
0. Rea( (ata i# ,-r3$ (ata area.
1. A$$ig# ,-r "i#: a$ N/LL.
4. A$$ig# fir$t5"a$t5,-r.
Ste! 4: If o!eratio# t!e i$ I#$ert t.e# !ro,e$$ t.e fo""o2i#g $te!$.
'. A""o,ate memor for #o(e ,-r.
0. Rea( (ata i# ,-r3$ (ata area.
1. Rea( t.e !o$itio# t.e Data to 6e i#$erti#g.
4. A+ai"a6i"it of t.e !o$itio# i$ tr-e t.e# a$$ig# ,-r3$ "i#: a$ fir$t a#( fir$t5,-r.
5. If a+ai"a6i"it of !o$itio# i$ fa"$e t.e# (o fo""o2i#g $te!$.
'. A$$ig# #e*t a$ ,-r a#( ,o-#t a$ 7ero.
0. Re!eat t.e fo""o2i#g $te!$ -#ti" ,o-#t "e$$ t.a# !o$itio#.
' .A$$ig# !re+ a$ #e*t
0. Ne*t a$ !re+ of "i#:.
1. A(( ,o-#t 6 o#e.
4. If !re+ a$ N/LL t.e# (i$!"a t.e me$$age IN8ALID POSITION.
5. If !re+ #ot 9-a" to N/LL t.e# (o t.e fo""o2i#g $te!$.
'. A$$ig# ,-r3$ "i#: a$ !re+3$ "i#:.
0. A$$ig# !re+3$ "i#: a$ ,-r.
Ste!5: If o!eratio# t!e i$ (e"ete t.e# (o t.e fo""o2i#g $te!$.
'. Rea( t.e !o$itio# .
0. C.e,: "i$t i$ Em!t .If it i$ tr-e (i$!"a t.e me$$age Li$t em!t.
1. If !o$itio# i$ fir$t.
'. A$$ig# ,-r a$ fir$t.
0. A$$ig# Fir$t a$ fir$t of "i#:.
1. Rea""o,ate t.e ,-r from memor.
4. If !o$itio# i$ "a$t.
'. Mo+e t.e ,-rre#t #o(e to !re+.
0. ,-r3$ "i#: a$ N-"".
1. Rea""o,ate t.e La$t from memor.
4. A$$ig# "a$t a$ ,-r.
5. If !o$itio# i$ e#ter Me(iate.
'. Mo+e t.e ,-r to re9-ire( !o$itio#.
0. Mo+e t.e Pre+io-$ to ,-r3$ !re+io-$ !o$itio#
1. Mo+e t.e Ne*t to ,-r3$ Ne*t !o$itio#.
4. No2 a$$ig# !re+io-$ of "i#: a$ #e*t.
5. Rea""o,ate t.e ,-r from memor.
$te! ;: If o!eratio# i$ tra+er$e.
'. A$$ig# ,-rre#t a$ fir$t.
0. Re!eat t.e fo""o2i#g $te!$ -#ti" ,-r 6e,ome$ N/LL.
Program
<i#,"-(e=io$tream..>
<i#,"-(e=,o#io..>
<i#,"-(e=!ro,e$$..>
<(efi#e ma* 5
$tr-,t #o(e
E
i#t (ataA
i#t #e*tA
IA
t!e(ef $tr-,t #o(e NODEA
i#t a+ai")"i$t 5 H'A
NODE ,-r$Bma*DA
+oi( i#itia"?@
E
i#t iA
a+ai" 5 CA
for?i5CAi=ma*H'Ai++@
,-r$BiD.#e*t5i+'A
,-r$BiD.#e*t5H'A
I
+oi( ,reate?@
E
i#t #)i)item)tem!A
,o-t==FG#E#ter t.e #o of e"eme#t$: FA
,i#>>#A
PP,o-t==#A
if?#>5ma*@
,o-t==FG# Si7e e*i$t$FA
e"$e
E
i#itia"?@A
if?a+ai"55H'@
E
,o-t==FG#T.ere i$ #o $!a,e to i#$ertFA
e*it?C@A
I
"i$t 5 a+ai"A
if?#55ma*H'@ a+ai" 5 H'A
e"$e a+ai"5#+'A
,o-t==FG#E#ter t.e e"eme#t$ o#e 6 o#e: FA
for?i5CAi=#Ai++@
E
,o-t==FG# E#ter t.e F==i+'==Ft. e"eme#t FA
,i#>>itemA
,o-t==FGtFA
PP,o-t==itemA
,-r$Bi+'D.(ata5itemA
I
,-r$B#D.#e*t5H'A
I
I
+oi( (i$!"a?@
E
i#t iA
,o-t==FG#C-r$or $!a,e: FA
,o-t==FG#G#A+ai" 5 F==a+ai"==F Gt FA
,o-t==FLi$t 5 F=="i$t==FG#FA
,o-t==FQQQQQQQQQQQQQQQFA
,o-t==FG# DATA NEXT G#FA
,o-t==FQQQQQQQQQQQQQQQFA
i5CA
2.i"e?i=ma*@
E
,o-t==FG#F==,-r$BiD.(ata==F Gt F==,-r$BiD.#e*tA
,o-t==FG#QQQQQQQQQQQQQQQFA
i++A
I
I
+oi( i#$6eg?@
E
i#t item)iA
,o-t==FG#E#ter t.e item to 6e i#$erte(: FA
,i#>>itemA
PP,o-t==itemA
,o-t==FG#FA
i5a+ai"A
a+ai"5,-r$Ba+ai"D.#e*tA
,-r$BiD.(ata5itemA
,-r$BiD.#e*t5,-r$B"i$tD.#e*tA
,-r$B"i$tD.#e*t5iA
I
+oi( i#$e#(?@
E
i#t item)iA
,o-t==FG#E#ter t.e item to 6e i#$erte(: FA
,i#>>itemA
PP,o-t==itemA
,o-t==e#("A
i5"i$tA
2.i"e?,-r$BiD.#e*tM5H'@
i5,-r$BiD.#e*tA
,-r$BiD.#e*t5a+ai"A
a+ai"5,-r$Ba+ai"D.#e*tA
i5,-r$BiD.#e*tA
,-r$BiD.(ata5itemA
,-r$BiD.#e*t5H'A
I
+oi( i#$i#t?@
E
i#t item)i)!o$),o-#t)tem!A
,o-t==FG#E#ter t.e item to 6e i#$erte(: FA
,i#>>itemA
PP,o-t==itemA
,o-t==e#("A
,o-t==FG#E#ter t.e !o$itio# of t.e item: FA
,i#>>!o$A
PP,o-t==!o$A
,o-t==e#("A
i5"i$tA
,o-#t5'A
2.i"e?,o-#t=!o$@
E
i5,-r$BiD.#e*tA
,o-#t5,o-#t+'A
I
tem!5a+ai"A
a+ai"5,-r$Ba+ai"D.#e*tA
,-r$Btem!D.(ata5itemA
,-r$Btem!D.#e*t5,-r$BiD.#e*tA
,-r$BiD.#e*t5tem!A
I
+oi( (e"6eg?@
E
i#t iA
i5,-r$B"i$tD.#e*tA
,-r$B"i$tD.#e*t5,-r$BiD.#e*tA
,-r$BiD.#e*t5a+ai"A
a+ai"5iA
,-r$Ba+ai"D.(ata5CA
if?,-r$B"i$tD.#e*t55H'@
E
,-r$B"i$tD.#e*t5a+ai"A
a+ai"5"i$tA
"i$t5H'A
I
I
+oi( (e"e#(?@
E
i#t i)!re+A
i5"i$tA
2.i"e?,-r$BiD.#e*tM5H'@
E
!re+5iA
i5,-r$BiD.#e*tA
I
,-r$B!re+D.#e*t5H'A
,-r$BiD.#e*t5a+ai"A
a+ai"5iA
,-r$Ba+ai"D.(ata5CA
if?,-r$B"i$tD.#e*t55H'@
E
,-r$B"i$tD.#e*t5a+ai"A
a+ai"5"i$tA
"i$t5H'A
I
I
+oi( (e"i#t?@
E
i#t !o$)i),o-#t)!re+A
,o-t==FG#E#ter t.e !o$itio#: FA
,i#>>!o$A
PP,o-t==!o$A
,o-t==e#("A
i5"i$tA
,o-#t5'A
2.i"e?,o-#t=5!o$@
E
!re+5iA
i5,-r$BiD.#e*tA
,o-#t5,o-#t+'A
I
,-r$B!re+D.#e*t5,-r$BiD.#e*tA
,-r$BiD.#e*t5a+ai"A
a+ai"5iA
,-r$Ba+ai"D.(ata5CA
if?,-r$B"i$tD.#e*t55H'@
E
,-r$B"i$tD.#e*t5a+ai"A
a+ai"5"i$tA
"i$t5H'A
I
I
+oi( mai#?@
E
i#t ,.A
,"r$,r?@A
(o
E
,o-t==FG# KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKFA
,o-t==FG#GtGtGtGt LISTG#FA
,o-t==F KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKFA
,o-t==FG#'. CreateFA
,o-t==FG#0. I#$ert at 6egi#FA
,o-t==FG#1. I#$ert at e#(FA
,o-t==FG#4. I#$ert at i#terme(iateFA
,o-t==FG#5. De"ete at 6egi#FA
,o-t==FG#;. De"ete at e#(FA
,o-t==FG#O. De"ete at i#terme(iateFA
,o-t==FG#R. Di$!"aFA
,o-t==FG#S. E*itFA
,o-t==FG#G#E#ter o-r ,.oi,e:FA
,i#>>,.A
PP,o-t==FG#F==,.A
$2it,.?,.@
E
,a$e ':
,reate?@A
6rea:A
,a$e 0:
if?a+ai"55H'@ ,o-t==FG#T.ere i$ #o $!a,eFA
e"$e i#$6eg?@A
6rea:A
,a$e 1:
if?a+ai"55H'@ ,o-t==FG#T.ere i$ #o $!a,eFA
e"$e i#$e#(?@A
6rea:A
,a$e 4:
if?a+ai"55H'@ ,o-t==FG#T.ere i$ #o $!a,eFA
e"$e i#$i#t?@A
6rea:A
,a$e 5:
if?"i$t55H'@ ,o-t==FG#No e"eme#t to (e"eteFA
e"$e (e"6eg?@A
6rea:A
,a$e ;:
if?"i$t55H'@ ,o-t==FG#No e"eme#t to (e"eteFA
e"$e (e"e#(?@A
6rea:A
,a$e O:
if?"i$t55H'@ ,o-t==FG#No e"eme#t to (e"eteFA
e"$e (e"i#t?@A
6rea:A
,a$e R:
(i$!"a?@A
6rea:A
,a$e S:
,o-t==FG#E#( of t.e o!eratio#FA
6rea:A
(efa-"t:
,o-t==FG#E#ter o#" ' to S: FA
I
I2.i"e?,.M5S@A
I
O/TP/T
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:'
'
E#ter t.e #o of e"me#t$: 4
4
E#ter t.e e"eme#t$ o#e 6 o#e:
e#ter t.e e"eme#t 0
0
e#ter t.e e"eme#t 1
1
e#ter t.e e"eme#t 4
4
e#ter t.e e"eme#t 5
5
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:R
R
C-r$or $!a,e:
A+ai" 5 H' Li$t 5 C
QQQQQQQQQQQQQQ
DATA NEXT
QQQQQQQQQQQQQQ
C '
QQQQQQQQQQQQQQQ
0 0
QQQQQQQQQQQQQQQ
1 1
QQQQQQQQQQQQQQQ
4 4
QQQQQQQQQQQQQQQ
5 H'
QQQQQQQQQQQQQQQ
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:;
;
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:R
R
C-r$or $!a,e:
A+ai" 5 4 Li$t 5 C
QQQQQQQQQQQQQQ
DATA NEXT
QQQQQQQQQQQQQQ
C '
QQQQQQQQQQQQQQQ
0 0
QQQQQQQQQQQQQQQ
1 1
QQQQQQQQQQQQQQQ
4 H'
QQQQQQQQQQQQQQQ
C H'
QQQQQQQQQQQQQQQ
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:0
0
E#ter t.e item to 6e i#$erte(: ;
;
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:R
R
C-r$or $!a,e:
A+ai" 5 H' Li$t 5 C
QQQQQQQQQQQQQQ
DATA NEXT
QQQQQQQQQQQQQQ
C 4
QQQQQQQQQQQQQQQ
0 0
QQQQQQQQQQQQQQQ
1 1
QQQQQQQQQQQQQQQ
4 H'
QQQQQQQQQQQQQQQ
; '
QQQQQQQQQQQQQQQ

LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:O
O
E#ter t.e !o$itio#: 0
0
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:R
R
C-r$or $!a,e:
A+ai" 5 ' Li$t 5 C
QQQQQQQQQQQQQQ
DATA NEXT
QQQQQQQQQQQQQQ
C 4
QQQQQQQQQQQQQQQ
C H'
QQQQQQQQQQQQQQQ
1 1
QQQQQQQQQQQQQQQ
4 H'
QQQQQQQQQQQQQQQ
; 0
QQQQQQQQQQQQQQQ
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:1
1
E#ter t.e item to 6e i#$erte(: S
S
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:R
R
C-r$or $!a,e:
A+ai" 5 H' Li$t 5 C
QQQQQQQQQQQQQQ
DATA NEXT
QQQQQQQQQQQQQQ
C 4
QQQQQQQQQQQQQQQ
S H'
QQQQQQQQQQQQQQQ
1 1
QQQQQQQQQQQQQQQ
4 '
QQQQQQQQQQQQQQQ
; 0
QQQQQQQQQQQQQQQ
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:5
5
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:R
R
C-r$or $!a,e:
A+ai" 5 4 Li$t 5 C
QQQQQQQQQQQQQQ
DATA NEXT
QQQQQQQQQQQQQQ
C 0
QQQQQQQQQQQQQQQ
S H'
QQQQQQQQQQQQQQQ
1 1
QQQQQQQQQQQQQQQ
4 '
QQQQQQQQQQQQQQQ
C H'
QQQQQQQQQQQQQQQ
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:4
4
E#ter t.e item to 6e i#$erte(: 0'
0'
E#ter t.e !o$itio# of t.e item: 0
0
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:R
R
C-r$or $!a,e:
A+ai" 5 H' Li$t 5 C
QQQQQQQQQQQQQQ
DATA NEXT
QQQQQQQQQQQQQQ
C 0
QQQQQQQQQQQQQQQ
S H'
QQQQQQQQQQQQQQQ
1 4
QQQQQQQQQQQQQQQ
4 '
QQQQQQQQQQQQQQQ
0' 1
QQQQQQQQQQQQQQQ
LIST
'. Create
0. I#$ert at 6egi#
1. I#$ert at e#(
4. I#$ert at i#terme(iate
5. De"ete at 6egi#
;. De"ete at e#(
O. De"ete at i#terme(iate
R. Di$!"a
S. E*it
E#ter o-r ,.oi,e:S
Result
T.-$) t.e ,-r$or im!"eme#tatio# of "i$t ADT for $i#g" "i#:e( "i$t !rogram .a$ 6ee# 2ritte#
a#( e*e,-te( $-,,e$$f-"".
EX.NO:R Sta,: ADTH Arra Im!"eme#tatio#
DATE:
AIM:
To Write a C++ Program to Sta,: ADT im!"eme#tatio# -$i#g arra
A"gorit.m:
Ste! ': Defi#e a $ta,: $i7e.
Ste! 0: Rea( t.e $ta,: o!eratio#.
Ste! 1: Rea( t.e $ta,: e"eme#t.
Ste! 4: C.e,: t.e $ta,: o!eratio# i$ P-$. or Po!.
Ste! 5: If o!eratio# i$ !-$. t.e# ,.e,: t.e $ta,: $tat-$.
i. If $ta,: $tat-$ i$ o+er f"o2 2e ,a#Tt !-$. t.e e"eme#t i# to $ta,:.
ii. Ot.er2i$e 2e ,a# a(( t.e (ata i#to $ta,: .
iii. Mo+e to! to #e*t !o$itio#.
Program
<i#,"-(e=io$tream..>
<i#,"-(e=,o#io..>
<i#,"-(e=$t("i6..>
PP-$i#g #ame$!a,e $t(A
,"a$$ $ta,:
E
i#t $t:B5DA
i#t to!A
!-6"i,:
$ta,:?@
E
to!5H'A
I
+oi( !-$.?i#t *@
E
if?to! > 4@
E
,o-t ==F$ta,: o+er f"o2FA
ret-r#A
I
$t:B++to!D5*A
,o-t ==Fi#$erte(F ==*A
I
+oi( !o!?@
E
if?to! =C@
E
,o-t ==F$ta,: -#(er f"o2FA
ret-r#A
I
,o-t ==F(e"ete(F ==$t:Bto!HHDA
I
+oi( (i$!"a?@
E
if?to!=C@
E
,o-t ==F $ta,: em!tFA
ret-r#A
I
for?i#t i5to!Ai>5CAiHH@
,o-t ==$t:BiD ==F FA
I
IA

mai#?@
E
C"r$,r?@A
i#t ,.A
$ta,: $tA
2.i"e?'@
E
,o-t ==FG#'.!-$. 0.!o! 1.(i$!"a 4.e*itG#E#ter -r ,.oi,eFA
,i# >> ,.A
$2it,.?,.@
E
,a$e ': ,o-t ==Fe#ter t.e e"eme#tFA
,i# >> ,.A
$t.!-$.?,.@A
6rea:A
,a$e 0: $t.!o!?@A 6rea:A
,a$e 1: $t.(i$!"a?@A6rea:A
,a$e 4: e*it?C@A
I
I
ret-r# ?C@A
I
O/TP/T
'.!-$. 0.!o! 1.(i$!"a 4.e*it
E#ter -r ,.oi,e0
$ta,: -#(er f"o2
'.!-$. 0.!o! 1.(i$!"a 4.e*it
E#ter -r ,.oi,e'
e#ter t.e e"eme#t0
i#$erte(0
'.!-$. 0.!o! 1.(i$!"a 4.e*it
E#ter -r ,.oi,e'
e#ter t.e e"eme#t1
i#$erte(1
'.!-$. 0.!o! 1.(i$!"a 4.e*it
E#ter -r ,.oi,e0
(e"ete(1
'.!-$. 0.!o! 1.(i$!"a 4.e*it
E#ter -r ,.oi,e'
e#ter t.e e"eme#t5
i#$erte(5
'.!-$. 0.!o! 1.(i$!"a 4.e*it
E#ter -r ,.oi,e1
5 0
'.!-$. 0.!o! 1.(i$!"a 4.e*it
E#ter -r ,.oi,e4
Re$-"t:
T.-$) t.e $ta,: ADTH arra im!"eme#tatio# !rogram .a$ 6ee# 2ritte# a#( e*e,-te(
$-,,e$$f-"".
EX.NO:S Sta,: ADTH Li#:e( "i$t Im!"eme#tatio#
DATE :
AIM:
To Write a C++ Program to Sta,: ADT im!"eme#tatio# -$i#g "i#:e( "i$t
A"ogarit.m :
Ste! ': ,reate a "i$t.
i@ Create a #e2 em!t #o(e to!.
ii@ Rea( t.e $ta,: e"eme#t a#( $tore it i# to!3$ (ata area.
iii@ A$$ig# to!3$ "i#: !art a$ N/LL ?i.e. to!H>"i#:5N/LL@.
i+@ A$$ig# tem! a$ to! ?i.e. tem!5to!@.
Ste! 0: Rea( #e*t $ta,: o!eratio#.
i@ If it i$ Create t.e# go to $te!'.
ii@ If it i$ P-$. t.e# it !ro,e$$ fo""o2i#g $te!$
a@ C.e,: Mai# memor for #o(e ,reatio#.
6@ Create a #e2 #o(e to!.
,@ Rea( t.e $ta,: e"eme#t a#( $tore it i# to!3$ (ata area.
(@ A$$ig# to!3$ "i#: !art a$ tem! ?i.e. to!H>"i#:5tem!@.
e@ A$$ig# tem! a$ to! ?i.e. tem!5to!@.
iii@ If it i$ !o! t.e# it !ro,e$$ fo""o2i#g $te!$
a@ If to! i$ N/LL t.e# (i$!"a $ta,: i$ em!t.
6@ Ot.er2i$e a$$ig# to! a$ tem! ?i.e. to!5tem!) 6ri#g t.e to! to to! !o$itio#@
,@ A$$ig# tem! a$ tem!3$ "i#:. ?i.e. tem!5tem!H>"i#:) 6ri#g t.e tem! to to!3$ !re+io-$
!o$itio#@.
(@ De"ete to! from memor.
i+@ If it i$ tra+er$e t.e# !ro,e$$ t.e fo""o2i#g $te!$
a@ Uri#g t.e to! to $ta,:T$ to! !o$itio#?i.e. to!5tem!@
6@ Re!eat -#ti" to! 6e,ome$ N/LL
i@ Di$!"a t.e to!3$ (ata.
ii@ A$$ig# to! a$ to!3$ "i#: ?to!5to!H>"i#:@.
Program
<i#,"-(e=io$tream..>
<i#,"-(e=,o#io..>
<i#,"-(e=$t("i6..>
PP-$i#g #ame$!a,e $t(A
,"a$$ #o(e
E
!-6"i,:
,"a$$ #o(e K#e*tA
i#t (ataA
IA

,"a$$ $ta,: : !-6"i, #o(e
E
#o(e K.ea(A
i#t to$A
!-6"i,:
$ta,:?@
E
to$5H'A
I
+oi( !-$.?i#t *@
E
if ?to$ = C @
E
.ea( 5#e2 #o(eA
.ea(H>#e*t5N/LLA
.ea(H>(ata5*A
to$ ++A
I
e"$e
E
#o(e Ktem!)Ktem!'A
tem!5.ea(A
if?to$ >5 4@
E
,o-t ==F$ta,: o+er f"o2FA
ret-r#A
I
to$++A
2.i"e?tem!H>#e*t M5 N/LL@
tem!5tem!H>#e*tA
tem!'5#e2 #o(eA
tem!H>#e*t5tem!'A
tem!'H>#e*t5N/LLA
tem!'H>(ata5*A
I
I
+oi( (i$!"a?@
E
#o(e Ktem!A
tem!5.ea(A
if ?to$ = C@
E
,o-t ==F $ta,: -#(er f"o2FA
ret-r#A
I
2.i"e?tem! M5 N/LL@
E
,o-t ==tem!H>(ata== F FA
tem!5tem!H>#e*tA
I
I
+oi( !o!?@
E
#o(e Ktem!A
tem!5.ea(A
if? to$ = C @
E
,o-t ==F$ta,: -#(er f"o2FA
ret-r#A
I
to$HHA
2.i"e?tem!H>#e*tH>#e*tM5N/LL@
E
tem!5tem!H>#e*tA
I
tem!H>#e*t5N/LLA
I
IA
mai#?@
E
C"r$,r?@A
$ta,: $'A
i#t ,.A
2.i"e?'@
E
,o-t ==FG#'.P/S&G#0.POPG#1.DISPLAYG#4.EXITG# e#ter -r ,.oi,e:FA
,i# >> ,.A
$2it,.?,.@
E
,a$e ': ,o-t ==FG# e#ter a e"eme#tFA
,i# >> ,.A
$'.!-$.?,.@A
6rea:A
,a$e 0: $'.!o!?@A6rea:A
,a$e 1: $'.(i$!"a?@A
6rea:A
,a$e 4: e*it?C@A
I
I
ret-r# ?C@A
I
O-t!-t
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:'
e#ter a e"eme#t01
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:'
e#ter a e"eme#t;O
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:1
01 ;O
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:0
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:1
01
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:0
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:0
$ta,: -#(er f"o2
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:4
Re$-"t:
T.-$) t.e $ta,: ADTH "i#:e( "i$t im!"eme#tatio# !rogram .a$ 6ee# 2ritte# a#( e*e,-te(
$-,,e$$f-"".
EX.NO:'C.' O-e-e ADTH Arra Im!"eme#tatio#
DATE:
AIM:
To Write a C++ Program to V-e-e ADT im!"eme#tatio# -$i#g arra
A"gorit.m
Ste! ': I#itia"i7e t.e 9-e-e +aria6"e$ fro#t 5C a#( rear 5 H'
Ste! 0: Rea( t.e 9-e-e o!eratio# t!e.
Ste! 1: C.e,: t.e 9-e-e o!eratio#$ $tat-$.
i@. If it i$ I#$ertio# t.e# (o t.e fo""o2i#g $te!$
'. C.e,: rear = 9-e-eQ$i7e i$ tr-e i#,reme#t t.e rear 6 o#e a#( rea( t.e 9-e-e
e"eme#t a#( a"$o (i$!"a 9-e-e. ot.er2i$e (i$!"a t.e 9-e-e i$ f-"".
0. %o to $te!0.
ii@. If it i$ (e"etio# t.e# (o t.e fo""o2i#g $te!$
'. C.e,: rear= fro#t i$ tr-e t.e# (i$!"a t.e 9-e-e i$ em!t.
0. Mo+e t.e e"eme#t$ to o#e $te! for2ar( ?i.e. mo+e to !re+io-$ i#(e* @.
1. De,rea$e$ t.e rear +a"-e 6 o#e ?rear5rearH'@.
4. Di$!"a 9-e-e
5. %o to $te!0.
Program:
<i#,"-(e=io$tream..>
<i#,"-(e=,o#io..>
<i#,"-(e=$t("i6..>
PP-$i#g #ame$!a,e $t(A

,"a$$ 9-e-e
E
i#t 9-e-e'B5DA
i#t rear)fro#tA
!-6"i,:
9-e-e?@
E
rear5H'A
fro#t5H'A
I
+oi( i#$ert?i#t *@
E
if?rear > 4@
E
,o-t ==F9-e-e o+er f"o2FA
fro#t5rear5H'A
ret-r#A
I
9-e-e'B++rearD5*A
,o-t ==Fi#$erte(F ==*A
I
+oi( (e"et?@
E
if?fro#t55rear@
E
,o-t ==F9-e-e -#(er f"o2FA
ret-r#A
I
,o-t ==F(e"ete(F ==9-e-e'B++fro#tDA
I
+oi( (i$!"a?@
E
if?rear55fro#t@
E
,o-t ==F 9-e-e em!tFA
ret-r#A
I
for?i#t i5fro#t+'Ai=5rearAi++@
,o-t ==9-e-e'BiD==F FA
I
IA

mai#?@
E
C"r$,r?@A
i#t ,.A
9-e-e 9-A
2.i"e?'@
E
,o-t ==FG#'.i#$ert 0.(e"et 1.(i$!"a 4.e*itG#E#ter -r ,.oi,eFA
,i# >> ,.A
$2it,.?,.@
E
,a$e ': ,o-t ==Fe#ter t.e e"eme#tFA
,i# >> ,.A
9-.i#$ert?,.@A
6rea:A
,a$e 0: 9-.(e"et?@A 6rea:A
,a$e 1: 9-.(i$!"a?@A6rea:A
,a$e 4: e*it?C@A
I
I
ret-r# ?C@A
I
O/TP/T
'.i#$ert 0.(e"et 1.(i$!"a 4.e*it
E#ter -r ,.oi,e'
e#ter t.e e"eme#t0'
i#$erte(0'
'.i#$ert 0.(e"et 1.(i$!"a 4.e*it
E#ter -r ,.oi,e'
e#ter t.e e"eme#t00
i#$erte(00
'.i#$ert 0.(e"et 1.(i$!"a 4.e*it
E#ter -r ,.oi,e'
e#ter t.e e"eme#t';
i#$erte(';
'.i#$ert 0.(e"et 1.(i$!"a 4.e*it
E#ter -r ,.oi,e1
0' 00 ';
'.i#$ert 0.(e"et 1.(i$!"a 4.e*it
E#ter -r ,.oi,e0
(e"ete(0'
'.i#$ert 0.(e"et 1.(i$!"a 4.e*it
E#ter -r ,.oi,e1
00 ';
'.i#$ert 0.(e"et 1.(i$!"a 4.e*it
E#ter -r ,.oi,e
Re$-"t:
T.-$) t.e 9-e-e ADTH arra im!"eme#tatio# !rogram .a$ 6ee# 2ritte# a#( e*e,-te(
$-,,e$$f-"".
EX.NO:'C.0 O-e-e ADTH Li#:e( "i$t Im!"eme#tatio#
DATE:
AIM:
To Write a C++ Program to V-e-e ADT im!"eme#tatio# -$i#g "i#:e( "i$t
A"gorit.m
Ste! ': I#itia"i7e t.e 9-e-e +aria6"e$ fro#t 5C a#( rear 5 H'
Ste! 0: Rea( t.e 9-e-e o!eratio# t!e.
Ste! 1: C.e,: t.e 9-e-e o!eratio#$ $tat-$.
i@. If it i$ I#$ertio# t.e# (o t.e fo""o2i#g $te!$
1. C.e,: rear #ot e9-a" to #-"" i$ tr-e i#,reme#t t.e rear 6 o#e a#( rea( t.e 9-e-e
e"eme#t a#( a"$o (i$!"a 9-e-e. ot.er2i$e (i$!"a t.e 9-e-e i$ f-"".
4. %o to $te!0.
ii@. If it i$ (e"etio# t.e# (o t.e fo""o2i#g $te!$
;. C.e,: rear= fro#t i$ tr-e t.e# (i$!"a t.e 9-e-e i$ em!t.
O. Mo+e t.e e"eme#t$ to o#e $te! for2ar( ?i.e. mo+e to !re+io-$ i#(e* @.
R. De,rea$e$ t.e rear +a"-e 6 o#e ?rear5rearH'@.
S. Di$!"a 9-e-e
'C. %o to $te!0.
Program
<i#,"-(e=io$tream..>
<i#,"-(e=,o#io..>
<i#,"-(e=$t("i6..>
PP-$i#g #ame$!a,e $t(A
,"a$$ #o(e
E
!-6"i,:
,"a$$ #o(e K#e*tA
i#t (ataA
IA

,"a$$ 9-e-e : !-6"i, #o(e
E
#o(e K.ea(A
i#t fro#t)rareA
!-6"i,:
9-e-e?@
E
fro#t5H'A
rare5H'A
I
+oi( !-$.?i#t *@
E
if ?rare = C @
E
.ea( 5#e2 #o(eA
.ea(H>#e*t5N/LLA
.ea(H>(ata5*A
rare ++A
I
e"$e
E
#o(e Ktem!)Ktem!'A
tem!5.ea(A
if?rare >5 4@
E
,o-t ==F9-e-e o+er f"o2FA
ret-r#A
I
rare++A
2.i"e?tem!H>#e*t M5 N/LL@
tem!5tem!H>#e*tA
tem!'5#e2 #o(eA
tem!H>#e*t5tem!'A
tem!'H>#e*t5N/LLA
tem!'H>(ata5*A
I I

+oi( (i$!"a?@
E
#o(e Ktem!A
tem!5.ea(A
if ?rare = C@
E
,o-t ==F 9-e-e -#(er f"o2FA
ret-r#A
I
2.i"e?tem! M5 N/LL@
E
,o-t ==tem!H>(ata== F FA
tem!5tem!H>#e*tA
I
I
+oi( !o!?@
E
#o(e Ktem!A
tem!5.ea(A
if? rare = C@
E
,o-t ==F9-e-e -#(er f"o2FA
ret-r#A
I
if?fro#t 55 rare@
E
fro#t 5 rare 5H'A
.ea(5N/LLA
ret-r#A
I
fro#t++A
.ea(5.ea(H>#e*tA
I
IA
mai#?@
E
C"r$,r?@A
9-e-e $'A
i#t ,.A
2.i"e?'@
E
,o-t ==FG#'.P/S&G#0.POPG#1.DISPLAYG#4.EXITG# e#ter r- ,.oi,e:FA
,i# >> ,.A
$2it,.?,.@
E
,a$e ':
,o-t ==FG# e#ter a e"eme#tFA
,i# >> ,.A
$'.!-$.?,.@A 6rea:A

,a$e 0: $'.!o!?@A6rea:A
,a$e 1: $'.(i$!"a?@A6rea:A
,a$e 4: e*it?C@A
I
I
ret-r# ?C@A
I
O/TP/T
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:'
e#ter a e"eme#t01
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:'
e#ter a e"eme#t54
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:1
01 54
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:0
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:0
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:0
9-e-e -#(er f"o2
'.P/S& 0.POP 1.DISPLAY 4.EXIT
e#ter r- ,.oi,e:4
Re$-"t
T.-$) t.e 9-e-e ADTH "i#:e( "i$t im!"eme#tatio# !rogram .a$ 6ee# 2ritte# a#( e*e,-te(
$-,,e$$f-"".
EX.NO:'' Sear,. Tree ADT W Ui#ar Sear,. Tree
DATE:
AIM:
To Write a C++ Program to to !erform I#$ert) De"ete) Sear,. a# e"eme#t i#to a 6i#ar
$ear,. tree
A"gorit.m
Create a #e2 i#$ta#,e of Ui#arTree.
Create a #e2 i#$ta#,e of TreeTe$t a#( $e"e,t Ui#arTree i#$ta#,e i# t.e o6Xe,t
6e#,. a$ t.e !arameter i# t.e ,o#$tr-,tor.
Ca"" t.e !o!-"ate met.o( of TreeTe$t i#$ta#,e.
I#$!e,t t.e Ui#arTree. It$ attri6-te$ are a "eft $-6tree) a rig.t $-6tree a#( a (ata
item.
Program
<i#,"-(e=io$tream..>
<i#,"-(e=,o#io..>
<i#,"-(e=$t("i6..>
PP-$i#g #ame$!a,e $t(A

+oi( i#$ert?i#t)i#t @A
+oi( (e"te?i#t@A
+oi( (i$!"a?i#t@A
i#t $ear,.?i#t@A
i#t $ear,.'?i#t)i#t@A
i#t treeB4CD)t5')$)*)iA

mai#?@
E
,"r$,r?@A
i#t ,.)A
for?i5'Ai=4CAi++@
treeBiD5H'A
2.i"e?'@
E
,o-t ==F'.INSERTG#0.DELETEG#1.DISPLAYG#4.SEARC&G#5.EXITG#E#ter o-r
,.oi,e:FA
,i# >> ,.A
$2it,.?,.@
E
,a$e ':
,o-t ==Fe#ter t.e e"eme#t to i#$ertFA
,i# >> ,.A
i#$ert?'),.@A
6rea:A
,a$e 0:
,o-t ==Fe#ter t.e e"eme#t to (e"eteFA
,i# >>*A
5$ear,.?'@A
if?M5H'@ (e"te?@A
e"$e ,o-t==F#o $-,. e"eme#t i# treeFA
6rea:A
,a$e 1:
(i$!"a?'@A
,o-t==FG#FA
for?i#t i5CAi=510Ai++@
,o-t ==iA
,o-t ==FG#FA
6rea:A
,a$e 4:
,o-t ==Fe#ter t.e e"eme#t to $ear,.:FA
,i# >> *A
5$ear,.?'@A
if? 55 H'@ ,o-t ==F#o $-,. e"eme#t i# treeFA
e"$e ,o-t ==* == Fi$ i#F == ==F!o$itio#FA
6rea:A
,a$e 5:
e*it?C@A
I
I
I

+oi( i#$ert?i#t $)i#t ,. @
E
i#t *A
if?t55'@
E
treeBt++D5,.A
ret-r#A
I
*5$ear,.'?$),.@A
if?treeB*D>,.@
treeB0K*D5,.A
e"$e
treeB0K*+'D5,.A
t++A
I
+oi( (e"te?i#t *@
E
if? treeB0K*D55H' NN treeB0K*+'D55H'@
treeB*D5H'A
e"$e if?treeB0K*D55H'@
E treeB*D5treeB0K*+'DA
treeB0K*+'D5H'A
I
e"$e if?treeB0K*+'D55H'@
E treeB*D5treeB0K*DA
treeB0K*D5H'A
I
e"$e
E
treeB*D5treeB0K*DA
(e"te?0K*@A
I
tHHA
I

i#t $ear,.?i#t $@
E
if?t55'@
E
,o-t ==F#o e"eme#t i# treeFA
ret-r# H'A
I
if?treeB$D55H'@
ret-r# treeB$DA
if?treeB$D>*@
$ear,.?0K$@A
e"$e if?treeB$D=*@
$ear,.?0K$+'@A
e"$e
ret-r# $A
I

+oi( (i$!"a?i#t $@
E
if?t55'@
E,o-t ==F#o e"eme#t i# tree:FA
ret-r#AI
for?i#t i5'Ai=4CAi++@
if?treeBiD55H'@
,o-t ==F FA
e"$e ,o-t ==treeBiDA
ret-r# A
I

i#t $ear,.'?i#t $)i#t ,.@
E
if?t55'@
E
,o-t ==F#o e"eme#t i# treeFA
ret-r# H'A
I
if?treeB$D55H'@
ret-r# $P0A
if?treeB$D > ,.@
$ear,.'?0K$),.@A
e"$e $ear,.'?0K$+'),.@A
I
O/TP/T
'.INSERT
0.DELETE
1.DISPLAY
4.SEARC&
5.EXIT
E#ter o-r ,.oi,e:1
#o e"eme#t i# tree:
C'0145;ORSC'''0'1'4'5';'O'R'S0C0'000104050;0O0R0S1C1'10
'. INSERT
0.DELETE
1.DISPLAY
4.SEARC&
5.EXIT
E#ter o-r ,.oi,e:'
E#ter t.e e"eme#t to i#$ert 'C
'.INSERT
0.DELETE
1.DISPLAY
4.SEARC&
5.EXIT
E#ter o-r ,.oi,e: 4
E#ter t.e e"eme#t to $ear,.: 'C
'C i$ i# ' !o$itio#
'.INSERT
0.DELETE
1.DISPLAY
4.SEARC&
5.EXIT
E#ter o-r ,.oi,e:5
Re$-"t:
T.-$) t.e t !rogram to !erform I#$ert) De"ete) Sear,. a# e"eme#t i#to a 6i#ar tree .a$
6ee# 2ritte# a#( e*e,-te( $-,,e$$f-"".
EX.NO:'0 &ea! Sort
DATE:
AIM:
To Write a C++ Program to !erform .ea! $ort.
A"gorit.m:
Ste! I: T.e -$er i#!-t$ t.e $i7e of t.e .ea!?2it.i# a $!e,ifie( "imit@.T.e !rogram ge#erate$
a ,orre$!o#(i#g 6i#ar tree 2it. #o(e$ .a+i#g ra#(om" ge#erate( :e 8a"-e$.
Ste! II: U-i"( &ea! O!eratio#
Ste! III: Remo+e ma*im-m e"eme#t:T.e !rogram remo+e$ t.e "arge$t e"eme#t of t.e
.ea!?t.e root@ 6 $2a!!i#g it 2it. t.e "a$t e"eme#t.
Ste! I8: T.e !rogram e*e,-te$ &ea!if?#e2 root@ $o t.at t.e re$-"ti#g tree $ati$fie$ t.e
.ea! !ro!ert.
Ste! 8: %oto $te! III ti"" .ea! i$ em!t
Program:
<i#,"-(e=io$tream..>
<i#,"-(e=$t("i6..>
,"a$$ $orti#g
E
!ri+ate:
i#t #)$i7eA
(o-6"e Kmi#.ea!A
!-6"i,:
+oi( i#$ertQmi#.ea!?(o-6"e@A
(o-6"e (e"eteQo#eQmi#.ea!?@A
+oi( i#!-t?@A
+oi( o-t!-t?@A
IA
+oi( $orti#g::i#$ertQmi#.ea!?(o-6"e #@
E
if?$i7e>5S@
E
,o-t==Yarra o+erf"o2 ZA
e*it?C@A
I
mi#.ea!B++$i7eD5#A
PPReor(er t.e .ea!
i#t :5$i7eA
2.i"e?:>'@ PP: .a$ a !are#t
E
if?mi#.ea!B:D=mi#.ea!B:P0D@
E
(o-6"e t5mi#.ea!B:DA
mi#.ea!B:D5mi#.ea!B:P0DA
mi#.ea!B:P0D5tA

:P50A
I
e"$e
6rea:A
I
I
(o-6"e $orti#g::(e"eteQo#eQmi#.ea!?@
E
if?$i7e='@
ret-r# H'A
(o-6"e +a"A
+a"5mi#.ea!B'DA
mi#.ea!B'D5mi#.ea!B$i7eDA
$i7eWA

PPReor(er t.e .ea! 6 mo+i#g (o2#
i#t :5'A
i#t #e2:A
2.i"e?0K:=5$i7e@ PP: .a$ at"ea$t o#e ,.ai"(
E
PPSet #e2: to t.e i#(e* of t.e $ma""e$t ,.ai"( of :
if?0K:55$i7e@ PPif : .a$ o#" "eft ,.ai(
E
#e2:50K:A
I
e"$e PP: .a$ t2o ,.ai"($
E
if?mi#.ea!B0K:D=mi#.ea!B0K:+'D@
#e2:50K:A
e"$e
#e2:50K:+'A
I
if?mi#.ea!B:D=mi#.ea!B#e2:D@
6rea:A
e"$e
E
(o-6"e tA
t5mi#.ea!B:DA
mi#.ea!B:D5mi#.ea!B#e2:DA
mi#.ea!B#e2:D5tA

:5#e2:A
I
I
ret-r# +a"A
I
+oi( $orti#g::i#!-t?@
E
,o-t==YE#ter .o2 ma# #-m6er$ o- are goi#g to e#ter for $orti#g :YA
,i#>>#A
mi#.ea!5#e2 (o-6"eB#+'DA
PKKKKKKKKKK Co#$tr-,t a .ea! 2it. t.e i#!-t e"eme#t$ KKKKKKKP
$i7e5CA
,o-t==YNo2 e#ter t.e e"eme#t$G#YA
(o-6"e #-m6erA
for?i#t i5'Ai=5#Ai++@
E
,i#>>#-m6erA
i#$ertQmi#.ea!?#-m6er@A
I
I
+oi( $orti#g::o-t!-t?@
E
,o-t==YT.e $orte( #-m6er$ are ::G#YA
for?i#t i5'Ai=5#Ai++@
,o-t==(e"eteQo#eQmi#.ea!?@==TGtTA
,o-t==e#("A
I
i#t mai#?@
E
,"r$,r?@A
$orti#g o6XA
o6X.i#!-t?@A
o6X.o-t!-t?@A
get,.?@A
I
O-t!-t
E#ter .o2 ma# #-m6er$ o- are goi#g to e#ter for $orti#g :5
No2 e#ter t.e e"eme#t$
S
'
R
0
;
T.e $orte( #-m6er$ are:
' 0 ; R S
Re$-"t:
T.-$) t.e .ea! $ort !rogram .a$ 6ee# 2ritte# a#( e*e,-te( $-,,e$$f-"".
EX.NO:'0 V-i,: Sort
DATE:
AIM:
To Write a C++ Program to !erform 9-i,: $ort.
A"gorit.m
Pi,: a# e"eme#t) ,a""e( a pivot) from t.e "i$t.
Reor(er t.e "i$t $o t.at a"" e"eme#t$ 2.i,. are "e$$ t.a# t.e !i+ot ,ome 6efore t.e
!i+ot a#( $o t.at a"" e"eme#t$ greater t.a# t.e !i+ot ,ome after it ?e9-a" +a"-e$ ,a#
go eit.er 2a@. After t.i$ !artitio#i#g) t.e !i+ot i$ i# it$ fi#a" !o$itio#. T.i$ i$ ,a""e(
t.e !artitio# o!eratio#.
Re,-r$i+e" $ort t.e $-6H"i$t of "e$$er e"eme#t$ a#( t.e $-6H"i$t of greater e"eme#t$
Program
<i#,"-(e=io$tream..>
<i#,"-(e=,o#io..>
,"a$$ V-iSort
E
i#t i)X)!i+otA
!-6"i,:
i#t #)aB0CDA
+oi( 9-i,:?i#t aBD)i#t "eft)i#t rig.t@A
+oi( $2a!?i#t aBD)i#t i)i#t X@A
IA
+oi( V-iSort :: 9-i,:?i#t aBD)i#t fir$t)i#t "a$t@
E
if?fir$t="a$t@
E
!i+ot5aBfir$tDA
i5fir$tA
X5"a$tA
2.i"e?i=X@
E
2.i"e?aBiD=5!i+otNNi="a$t@
i++A
2.i"e?aBXD>5!i+otNNX>fir$t@
XHHA
if?i=X@
$2a!?a)i)X@A
I
$2a!?a)fir$t)X@A
9-i,:?a)fir$t)XH'@A
9-i,:?a)X+')"a$t@A
I
I
+oi( V-iSort :: $2a!?i#t aBD)i#t i)i#t X@
E
i#t tem!A
tem!5aBiDA
aBiD5aBXDA
aBXD5tem!A
I
+oi( mai#?@
E
V-iSort o6XA
,"r$,r?@A
,o-t==FG#G#V/IC[ SORTFA
,o-t==FG#G#E#ter t.e "imit : FA
,i#>>o6X.#A
,"r$,r?@A
,o-t==FG#G#E#ter t.e e"eme#tG#G#FA
for?i#t i5CAi=o6X.#Ai++@
,i#>>o6X.aBiDA
o6X.9-i,:?o6X.a)C)o6X.#H'@A
,o-t==FG#G#T.e $orte( "i$t i$ G#G#FA
for?i5CAi=o6X.#Ai++@
,o-t==o6X.aBiD==F FA
get,.?@A
I
O/TP/T:
E#ter t.e "imit: 5
E#ter t.e e"eme#t$
5
4
1
0
'
T.e $orte( "i$t i$
' 0 1 4 5
Re$-"t
T.-$) t.e 9-i,: $ort !rogram .a$ 6ee# 2ritte# a#( e*e,-te( $-,,e$$f-"".