UNIT-3
ee ey oe,
Seong Cinted
ntatron
Liste
brorlteal uxt.
pst, Single Urrlted best Mi Auoye . repre
dektio,
Advantage @ olicacvantages ef
ad
mmemoty , dpetations — touertrom?
om Of © Stacle_,
Liokedd Lfet 2
Im plamentatr
wurrg
Uprlled LSet:
a
display » Search,
pyaled lst Grol, Uneed bee, Ceube
Some lab Phy
Shuctaa.
ftem hat © be
Some late
Or the antoldlly, Correroltabee
fn the Stare clels
sorseetid
7D Hem,
hae “be
Pom the tay
oa «OF
somoved
Bis uae” op gs date muvee OCCME-
'
4
4
,
'
s
’
osama dat, movement aneruied
y
’
’
d
Covttuenes Comput
Wy og egdtevenay .
nnéd witn tamscannyt uo the —dlitadVontage ot Lito brew ol TH (tabic
dota ctriebiu -
S mp ovarcons thin’ Probar! oy Stebe dota Chrudlue
Canay), lmited leet data Shuctur & Used -
dots Struetun , “0
> an th tinted — lint
and daletiom fon
in involved = tA Intertin inte
Le mitt, of the list
—> an _ Lalted - tigt date Strudue , th clement eed not
Ibe Rtoted in Consecutive omemeoty locadtromt - Alto, the
imecded te the elements fF tre Ubst
ablated begore hand -
Foe the elemonti OF the
memory Cpa
need rot be
D> The Memes Space allocatid
tice Can be extended Of any tim. that is hy
Lalted - Uist dole Stmichur th Called dynamic cafe
> an ts Caley Stette date ctuctars Coutay)y each
cuawent till hove aly thu lala fred bk
dynarie ltastrictine , Coch Clement FU have 20 type
of freloe, vemely, olebe field & porte freld .
ee aan etiad ate Tu pormler prety
hos be vides of Next elemed |
oo ATITET WITT CAMISTAN
in> The follow
g fig — Shows tie Cfrueliue of an element
in a limlted list -
pols Malt
> Gon to thy next node 4
ul pra oot ate ede conboing
Neat poles The
mull other than a Valtd pda ae ee mull porrta
and Imelidoatet stu end of fhe Ust -
frost 91Cole
a potnter to the Very
at u
le enttre
nal pormbs +
eatuane! ports
tte Umlted
ee we ennbls Us te acces t
a
Limited Ust +
efrnttten =
defen :
A Lenlted Ue a
Pinfte homo qenrout
the Liment ctols
potalire .
ane United Git a Cotegocised & & Four category
> Urea ot Storgly lintad Use
D> ctecutag frulled Uist
> doubly tinted lise
> etatuloe doubly bolted Use.
Anb .
yrove — Mmemety allocetion +
Gince oc up a Sruchuad language » Pe has
fee Fd le fee ane op ft fclucles
changing the SFE A an attay. An Oe A collection
location .
of Tkemg Stored at Contitivout oviemory
a |. 2 2 Cree:
Ciro [esl be Leo be ES
Ae re can be Seer that tes length OF the arteay
at 2 ee ee
au needed fe te entued
3 indices
iy thet attay 2% this
element
cue Jute wathing memety,
Seed
emote Chimay
ghualion, hus WF need Pout
go the = Gngth
allocation
ee
Mamoty AUocotron ean be
of a olata
There feu Dymamte
dayrned % & procedum rstuch the SPR
Struc He iw chongeot oluring Lhe Buntime. C Provide
Come —-functiont to achiewe thee tatiey , The, an
libwary functtors anh ate lefimed Und 2 ota tb
b>
Ee TT Cases,
Ant
'
|
'
'
'
|
'
!
'
heacke fie» They ate
> mallort )
> calloct >
> freee c)
+ Seabltoc ¢ )
malloc >
awe
> walle & omemoty allocation wotiod wc uh ued b&
dynamrealty allocats a Morgle large bloc of enaty
toith ty Specr¥red tise.
> 2t reuns a potmtu Y type Vord lrhich can be Com
= ‘ blo
Inb a porte 9) any fetm. at tnceralizer each |
woth —dlefanle gatbage value.
fyrtax: pty = (cast -type ) matloc Chyte -sr22)
pty 2 (ime 4) malloc (100 # srreoy OrE))-
Stebeme nt
a
cinte the Sizeq me G& Y byta , thu
wit! allocate 400 bylry Of memoty - And » the potorte
p& hold the adolen of te firtt byte am the
allocatid memoty .
Su byes
int gper 2 Ciné #) malloc CE Gz Cont) ;
Pty = A loage 20 bytes memeey bloc
S20 byte of momen — A clynamecally aitocatey te PA
Tf Span a Incutprcreng | locaton falls € & MULL pte
ned witn CamscanniExample»
T& progeam on malloee ) &/
He imeluda
th tmeladk
Int moatne )
£
fim aepey 5
fut n, i;
patos C\nent number 4 elementi ")5
Seanp [y.a" 2n);
pty = Cint #) malloc (rt Sizee, Om) 5
it (pty =2 NULL)
&
pate (" Memory mot allocated wnt)
est (03);
4
lye
£
printf. Climanuey Guecerfally allocated Utemg mall”);
foe (F204 tense)
pevit dete,
pointe Uvthe element of the a 7
ot (he 0, Pens Vr)
pombe ("7-dit") ply fi,
3
‘\potian 0;number 67 elem nf
nh
Luce ete tally
cece tally alloca ted cueing amaltlye
i
\
i mote
| memoty
| ;
} she clomonds the attay aw; 1 2% us
I te
}
' calloc >
+ Ly cocltoc Bi Comtrgeact allocation method th ¢ & cuted
1
, fe dynamically allocate fe Specified mumber Of blocks
type» 2b jorttra li zet
ol pmortoty 0] the opecttred
each bloc evith 4 dayault vole 4 ‘0
Sybase = pry=(east bype #) Calloc (n, element Gites
gp) calloc (28, ergeny (Fleot ys
ex! ptys (ftoot
atnix Stetemont odlocat — comtrguevs cpa GH menoty
4a 28 elumonti each with fie Stat pha | Ploot -
oo fy by tes
ant xP = Cent 2 callloc Cs, Srgeop (rat) 5
ply = © blocies 6 § byG each
oe es a ve olynantitally allocated
fo ph
ag Space u foageeppte Fert , alloca fatlr and Setiung
a Nuce pointe
| totom ple +
oA
J Progam o™ Cabloceyx /
He imelude. <6bdi0 bh?
He include < tht lb -h>
~~scannec ,
cd witn GamscannInt omaine ) oh
fy
$
tnt ph > “ho
ae ” ee de - alt
panty (Wert owmber ol element") SN
sant! Yd", £m); Spy fants
pir = Crt at) calloe Cn, s13eeq (int); Syn te
rf (ptr = =NULL) — oan
| babe
| ciate [yiemony snot allocated "): Spy a be
exit (0); : ° c
x oy
elte ony int
| 3 ate. ("Wmemouy Succerpully Ablecalad Ubing Calloe"): |
Pot (feo; Fens M+) ¢. ’
pew [rast +15 “
Ny.
point p (lithe elven oj the tay me "DS
| foe CF=0', fen} t++) ly
pantet 7-d ve, pee LPa); Ss |
% 5
seliun 05 Sr cxawn
or eae.
: re
outer: So ge
ents mumbu 6) elements 2 =
ttt
zr
Yt
&
Memory guecervpully ollocatid tums a llog
pace cheval “Tle URAy Oe SA, ic
Lf
f
Scanned with CamScann:freec )
Bee ometned % uw uted to dynamically
allocated Using
de -altocate The wmemoty, The — menroty
functors matloa’) ard calloc6 ) Ww Mee ale, allocéhes
on Crete OV Hence the Freel ) rotiod U- Wed,
txheneves the Aymande — wemecsy allocation falters place.
helps fb edu wastage of wromaty by Preeing HL,
at
Syvtax: bree Cre);
G bytes
int EPL = Cnt «) collog Co, Stseqy bint) 5
per = Cuut? S blocks 7 te bytis cach
ae UL cbypramieatty allowty
0 byt —
t ply
“y
Operation oom PEE
Pree (PtY
. + 1
‘The Memory 0}
Exomple +
Exons
Apoyo oo Prac) #/
terndude
ft Include ¢ Std. e-h>
tn maind )
$
Ink ptr, #PHY)!
Poke nytt
~~ Scanned witn Gamscanniporte (ert th nunber of Clementi
gean€ O 7d" 2n)
alloc (n p 81224 (mt) ),
pey = Cit 4) ™ (n La
= (rata) collec Cn, si30q 0
per! :
rg (ptysenver tl pevizenuee>
: pate (\yeneoey reo ollocated "J |
ext (ods
3
ele
£ olloctid Us omalloe’)
pane (Ywmemory Cuceert fully
fece (PEOL
patel matloe memacy succes freed te ‘
in 7 i
cate CM Merny Suceensfully allocatrd = Ubing ie
pra
peciys ce
TE ee calloc wemby Guccertjubly Freed );
pen
%
Salum 02
&
QUTPUT+ : :
ky tH cqrumbe oy Clemente 2s
: guecereslly allocadid — Xbnig malloc
Memnoty
tnallec momoly cuccerspelly Peed
oy cuccertgully alloccth¢ wiry — Calloc
Mow
collec amemtuty Cucceypully freed -
scanned with CamscannAealloc C )
wer
Scatloc
oS Re allocation method cc iu ed te
Aagyna matically change the memory allocation OF % pre viouwtly
allocated memory. Jn Other tootelr , PF tte. | remarry
ul
PrevPoutly allocated — toith tie help oy malloc Aw Calc
Ww MnSujlitient , ealloc can be tuted to oly nomnically
a] Emory Macon teens
wr be
80 -allocat memory. re - allocation
pretent Value blocs
the alteacty and new
ttt — dagarult
peat ply - seatloc Cpe, meu9eeeé) 5
garbage value.
Itt iclized
gyniax
hee ply ik venllordted Gotth Meas Ste
to
bye |
& al |
Soest : |
fat PHY = (int 4) malloc CS esr204 (root);
pee = (CPS A tte 10 bye many
> block a *dyranucotly
20 bryley of PMY
allocated fj phy
ple veallor (Ptr, lo #S3eq (at)) J
ee
fre
f ho byG 6] memey —> changed from Lolyta
t . . $40 byl olyranucey,
aR Cpaw u my Suybrlent, allocabr fails’ €- sefans AlUeL
eee
Jt Progam on Jealtoe ¢) &/
Imeluok < ¢td10h>
fe trcluele < ed's -h> Bo 7
SS ~~ scanned witn Camscanniwwe maine )
9
$
nt RECS
ink nts
pernbee Chin knee pamaber py eoveweite")!
coang (7d EMS
phe = Chol yp) collar On, tay ay Uta)
Lf (pte » NULL)
3 fonda (Sin penny not Cloratad uy
anit (0%
%
elit
+
pant Ciymiomoty
afye Cie 05 Fen Peey
peaflt: iat
Cote arco
fucoevcllyy oMoootid UMag Color"),
gaint f Of ‘lhe Ontny 08 My
for (fe 05 fans tha’)
pried C17 ANE "phe $i 0;
%
point? (3 In Emly lhe Mew? Bike, of as a "),
ceane ("%d", Bn) 5
per > Bealloc (ptr, n# heyee (tnt) \;
mp Lin Mamnote
pomeg [Nin Mananty fu ccen tilly 26 allocelig Lig
Soalloe")+
46 (feo fenjite)pey £PV< Pts
promt Clete elements 0) the Attay Ate "J:
for (FO; Ten; her)
perate (“%el bE”) pees,
free(nd;
Bebiun 03
5
OUTPUT =
—
=
Cok, ‘the Mumber 6 elements. =
Ent the
ted Witag Celloc
Mentos Seccers fully allocate 4
e]
‘ ee a
Hi the Utlag Aes Fe
athe clementi of
eEnta th mewsize gg bhe Atay 10
ie LU
Suceestprdly allocatid lutag vealloc
Maemecy
bee ES, se tf ate
che -glemonts o) Me MOY
scanned witn CamscannSierg le Lintaad -Ust =
Deginttion + A Giongle United Ust A @
linked lth. 7
which each mode — Comtaint only ome Lear. bred
the Lee,
Poimtmrg — be the Mert Moelr &
tthe — Following Pogue ghows the Logteel
aepreceatotion of 8 sorigly tenlted et -
— DATA LIN 1a “p bare Lie,
A PTH _ bf
on thin No Uinx(MUee)
yocde
th the above Pogute. the Weng fest Ode
called the header mode Whin "0 dob, elimert & Stored.
SS
lint fteld holds tte adder of Me ody
dale, olement-
et the
Containing the Very fase
Hen, once th acter gq the fheacler node iy
Knows, tr late freld 6) thd prec, C99 be Used t
Tdenkigy th vuxk mode and go on few the enbre Gngty
tilled lit Can be traveuted ,
an the Storghy Urrtked Use , the elumenti Can be
only fem Lete lo wigtl The Otherroay Mer
Lravetted
pothi ble. That wb tohy thu Stmgty Crnted Geer i lho coll
as me-woy lit.
0 erm comic
niApplicatiory y
> polynomial manipulation Samplumentatien of Stacles
ores
2D Dynamte Storage Management
> Am plementation of Farha
> Gorbase ¢ollictroy
es Abin, aie
> Ruddy systerrs. > Beprerenting ¢prue malig
G priked URES
Advartage and dicadvantage a Saagle leriked O6E
COE BN AS
Ad vantages!
~ Poe ward A Nech oy
in th
> accenibility a mol om “
QB carrey
> tnseebton & delehom 0) modes Ate Catrey
Hy Space & mot Wasted at we CaM Get Pace
a> MH
(i dye mont
aceowding fe OM Dogpurre Monts
> ome & mot Fred.
be Stored tn Comte cutive
mmoay ob May MOE
> Element u
$ the deta.
ant AVETASL, OVER then we Can Store ol
ame moty)
Ditadventagec:
vee
sak Seqiiver Mou Space 4 Porrtey cr AO Stored.
a Tine Comtummng
_> ae we want % Gols ao partiulet Clemene then we
have go theough att thoce elemente that Come befee iz
> we can trae form the beginning but not Frm fae.
> Sotteng of elementi U MOL eaty,
scanned witn CamscannSirigle: ected! St te Chet :
Re Lrorltod ling ot
lew ¢
sataies * oe :
© se cer the Stake yremay | O ae ee the clgviamic
allocatrem memory allocation,
© memory iv allocated ot compil]@) Meroty i atlocated oh
acne aun Etme
@rhe clement: ase Stored in [OTH lemon Que Shred iy
Conbioruoutty — memoty location
@ me accermg
any Avatlabe mene y
locatiary Uttng Pomc
@ the acceretag & Soyer
@ he Imseeteon and deletion 6) the trtertion and deltting
toom Any positim & trme Be Udk easy
Consuming
Representation g Uinked ee et Ce’
Vigtied (eee Can be Sepererented ON memory by
using fo AalLaye DATA and CINIe Sorpectively «
pata tomtaing —loefutmation 9) element and LINK
contarns rent Ook Coldlres, |
the Uodted Uet — Séarte tatty HEADER — whe
Conkeung tte adolerx of] free} rock, and Potrtly dreld
scanned witn Camscanno¢ late goede —olenoled by vee rotureh indveoks thy
end ogy beer
The treed Wee CON be eperenentzd = tn TEmery
ay follows
Heaner a
4
a te
Opesotions +
aa
the | Opevationt that a Perfcored -on Strgly
Lenleed lice ase:
—> Intestrey > Ditplayan come
to-h>
|e Progen
fetmelude ste
Gtauet rede
<
z ;
ww data;
ent,
cemet mods MEME,
be
Bteuct rode thud,
voig touted CI;
vord dele C5
vord dfeploy ¢ 3;
Void Seasch ¢ 3
fmt C20, boo:
Void wom )
i
fod ChE
head = NULL:
ao
f
Porertf (“i Pesterlé 2. DecerE \t
Se Aree“)
perf Cw Eats ae choice "Js
soane xd", Gk) -
a Seannea witn vamscannSuottch Co h
g
Cote 1: forgert Cds
olisploy C5
brealt;
Caw a: oektec ))
Arspley 695
break;
Cau 3: geaschC)s
adbveole 5
Cayaule » Patt (! 2nvalrd option!
petntf (Qn ts Contmue");
ccanh(" rd! Lads
%y whi (a==1);
%
Void teterec )
$
fmt pion:
Shnuce Hook Fhemp> (Shuck node 4) malloc
Csieeoy Cetrut niocld));
Chuck mode ¥bempa2 :
pointe (“in Emty tre element and ity Postion").
Seank(" Aa rd", GN, BP);
scanned with CamscannC pesoll poet!)
punt? ("in entire 8 valid position an
elte
L
crt
temp > data ="5
temp > next = NULL
(pest)
. heods
temp > next =
head =temps
3
ele
-— = head +
fe (i205 fe p25 14+t)
fempr =temp2 next +
temp next = Eemp> D noxt ;
temp2 > Yext= temp!
scanned with CamscannVold deletec )
§
Ine pts
Stouct mode xtemp! = head, #tomp2:
painbe ("Wn Ent the positten Remy which data
hot to be wemoved ");
geanf (“yd 2p);
if ( P<=o [| Poe) :
parmeep CoM Enlan a Valid Posithin):
ele
z
Co
re CP==1)
£
head = Eempl Snexb >
free (temp '):
4
che
z go (P20 5 P Mert 5
femp> = templ 3 rext!
femp/ > next= temp23 hee;
3 freeCbemp 2)!
y4
scanned witn Lamscannivord Searche >
%
mt on, Peo:
Stree Ode
pombe (" m gortin te elment f be Seaschad ");
Geanp (*%d an);
x= heods
whi. (%] =NULL)
§
P+ts
4g (x @ dela ==)
£
bel3
break 5
%
me 2D rexts
a
ve (be=D :
porte (87d th found a Pelton Ye 2 dat, Ps
elie : /
pamtf. (“Yd Olement not found’; *>dada);
scanned witn LamscanniVotd dieplay¢ )
: Stuck VWOde x
X= head ;
tohtee Cx J=NULL)
£
ponte (vd >t ddata)
Ma rD Next 5
3
4
OUT PUT =
1. pMseet 2. DELETE 3. SEARCH
tnt ur chore |
Eta the Element and ff positim 10 |
lo:
Press | be Continue |}
t- (INCEer 2. DELETE 8 S€Arcy
entra ut chore |
Enbr “the element and ty Position 20 |
40 > la>
pres ( ty Cortinuy ff
LaTNSeer 2 DELEIE 3 StARCHEE
Ent tye element ard Pe Position. 30° 3
20 S10 530 5
prec | f& Contine |
1. ENS eT » DELETE 8 starch
emti tur Chote 3
tnt ty eliment lb be Coached to
to ck found at posthion 2
peer here!
| 3 DELETE g ceareny
eEnta wr chota 2
eta te Position fem lee dala het Te be
Seruved |
103307
pron ¢ fb continu 21 Te pl eophementatron of
| MAREE AE Sle ting Lionted lice
/[& Progam om stoce
using — United Uat /
Héfoclide ate doh>
Struct node
a
Port dato,
Struck role next}
By
stuck ook theads
Voted push Cimé)>
tet popdd;
Vortd drspley Cj): -
Votd woe )
; fork 1, A,P, ths
heod = NULL;
do
£
pemef (wrt Push (2. Pop");
pombe (Centar us chou");
Seangl* rd! €ch);
Sestteh (oh) s
£
Cote [2 Prmki(lin eit the clemene & be
brekee Ceol (1) 2
Scang (td! Ln); : :
a § “ocr wit Camscannipush On) s 5
display t); §
‘
4
break 5
Case 2: re Cheod enol)
pambs (1 Stack Underflow’) 5
elite
$
$
papopdy:
point CA The deleted clomag & 74 P);
I displey 0):
x
break 5
dajoult . petal Pin grvolid pptron"),:
y
print Cm pes 1 to Contin")
geanf (" ¥d" £0)5
Zohib lazz)s
y
Vora push (int
)
$
3
cia vode HbertP = (itruct ode 9») omatloe CL eraeey (Shuck
‘ moole))!
temp 2 clela ="5
temp -> yeoxt 2 heod}
head > temp }
LF ___— rTM CEST
ntmk pope )
2
Mt 15
qtouet node # temp! = head;
ee a
head = temp! Drextl
fee (temp 1)
Sefiun 1)
3
Vota dit ptay( J
g
Chuck mock #25
x= head s
pik (x! =NuLL)
f ” :
Pome ('7-d -7 "x Ddata )s
Me n->rexts
3
3
2. POP
ext, ut chola |
tia element fo be Mtherted I
l->
pres | le Continue /
{- Push 2 POP
Ents we chore |
scanned witn vamscannelument b be mated 22
Ent the
Ul => 22-7
pe | Coot
t- PUSH 2. PoP
Enta ue choteo |
Gat ft, ela |e be mmiahs 22
tt 22-7233
pen [| & eetede |
1. PUSH 9 - PoP
toate ex ehote 2
the delbd element & 39
ores | ee Conttaue |
t- pure @- POP
tnte ut cholic, 2
anveltd Optto
oe | te Coe
scanned witn vamscai
'
t
’
'
’
’
’
’
’
nhAmplimentabon af queiteg sia
nnn Ass
[& progam on queust ting Limited Lect #/
HE tn clude
Struct node
Struck node Anexrt;
re
tat. C=04
Struct Mody heal 5
Vora encprete Crt) >
tnd deqwaut 635
Void dtspley 0):
Void mathe >
g
mt 1, Ab, ch;
head = AloLL S
do
£
probe (“1 EMQueut (E 2. Beaueue ");
brmep (“in Ember wr Charen")
Scone ("7d") ch);
Susttch Coh)
g
a ~ scanned witn Gamscanni