DATA STRUCTURES AND APPLICATIONS 150533
MopuLe 1] Imtreduction to Data Structures
I A ae te Apuseliged format fox
: fotgamizine, end Atoring deta .
! Dolartnchnee are clamitiel info Q shapes
(O Linens dettaahnchares
(i) Non-linean dataatmmehwres
the clements a dela ahaclure one Abred
_ Seapacrrbally then it & “calles! linear detachnebvre-
t J cE " shawks Queuee and Linked bisle -
i els Frnelite ase not
a doved tm requertial “orden Inge it le Called mon-
— linens del,
Ge: Trees ant Graph.
che. primitive, deka types one the bbaric debe hyper
Het ore available in _ameoat sf the. progam mun
Vomeanaget. The prenihes dats hyper ate ured a
_ nepueserd, dingle value
fat ches tof poet dole Ae. __
cher ello = - =
ind m= 6) ae
fleet 6 = 22)
athe. sada tapes lak ase derived Ta palonars
dala kot an Non- paanitive doh
_ There. dla eh ane Ured te « ise ou v.
Nen-primidive cleda type is alec Called a2 derived dota hype =
Exo Array Strachere, Onion, Stack, Quene, Linked lit ete.| handay
NQaeijmde Hebe Fendi} 4
| Ty the idewtipia ce met defined, theo ip clays
end tornpiled and exeaded. otherume, cle
or tindude: tionh
ckdefine E EN.
aint (Aste bard ab);
cea; dea: \
aienty (* Cad,Arrays and Stings
ped ie ao are 2 E AS she fi arahion “awn.
peek a ge a ay h geod live dimensional arrays —
wih an exemple? fae a Z
; ~~ ) - ;
Whed ih am arrey’ Hoe ina Binge dimennon array
Uta Aeclared and “intialiged?
ioe an exon? Hove te declare and ihalje
the Whe hoe aomenaion ee a
An array wa collection
Comaiatin “Fetatet dda tern a same oe mH
% 4 a _
emery all the dads iden ane Strela Conk
= meron loca
*Declarchen | Soplay | _dalabype erreny- name Lae] a
where dota type. Apecegien auc nd kind ag Vales ea
9 Atere ath 22 inh flock.cod
Triteligahen: Sigolax | dodahgpe ewreumame [ig] -S4 M Vnis
phere dodahype Apeciger tole kinel of Values on
_ array tom Atore Awh on int) fled, Choa ete
array mame Ka mame to _ideyhfy an array ‘
amd it & aval ¢ idenhage
Sige Apecigice The maxivmuim number Ff elemenbs
an ervey tam aleve and if must be an imesh
Value (4ve) er Vasialle
Vi Var. Nin axe the Wat of values enclosed roithin
_ Gy end Aeparated bey Comma
Ecomple tint als] = 410, 15, 20.85, 303; ” y
[re [is [ae Tas [se] __ _
ate] at] ab] ab] at]
Exeplkaitnd als] = ilo, is.a6c3s . E
(ie [is Tx Tee)
ae] at) bj] ai) st)
Exampbs tint af 1 = $10, 15, 20, 25,303 |
(re is ae |as [se 1
at) al] aG) al) at)
Exam yt iol ated: :
atel=\o) —_ a
aly =i55
alzj}= ao /
Exaropl ot Int as) = $10, 18,20.25,30,253, [LEGAvreau vsith theo chmenaions are called shoo i
tckanendiond av A +a dimensional ¢ array ta
area <3 5 Aub
ese Aubacripla, tshere fe
; ide 3" ag] [colwrne
ee where cledatype 2 pecigice tolwd kind gt Values on arrar
com store auch as int, ses ed, char ete.
ay mame is a same to | jerrtigg am eskag emd it
val” c iden biger:
rf rene bythe anny
Aige Apectpier the maximum um a Colimna ba
atelte) | ately | abe)
atite | atin] [ate]
, \abite | aPity abies |
atsits) | fon) [aby by
Column ©lighere dalahge Apeciges that kind ef Values en
_orrey tom ahore pcan fats plead, cha ete. ¥
ervey name U a veme do identy, on array
and this a valid c islersb.ger.
‘RWHZe Apedperthe marionum number ef reed ' the
ren J
_! colaige espe she maximum numbes 4 Columns
tn the ar
Ais O3,-- Any are Hye Valuer Aaa goed to Of vets
ou bay bn ere the Valuer arnguedd tp 1 010 & Boon.
Exewmple i int alaltal=¢
L1e, ao, 308,
£5, 10, 15%,
$100, Joo, Bec} , 7
T24 ey
33
Exaroplea | int _alAl[zl= flo, 26,30, 8, 10, 15, 120,200,
__ 300, % 46 35
Examples tet aL tale§
0, 20, 30, B10, 15, Ie, 200,
ase
Example 4 tind al TB]: f1¢,40,30,3,5,113 |
Exempt 5 cht af T= feze.se 3.8.75 [fTTye menbien the type g ota 2) Explain vst am exam
7 theta te acce the Vdlermmenk ep ta own?
OR
: cExplain the alep inyelveal reading amd wechinge
ise chimenss ere ia
a
Arrep ave clewnigich trl 2 hype
enaienal aves ~
errienal anrag- 4 + 7 5 _
For accemoime, 00 imetivicdmal elerment ef ei
“dianenaional aroha, the array aubacsipl sual be
Eye int atsl; io
vaccean te tnd ale] et dlemd alge
wing afd threngh a[] we can accom 5 interna:
ae ming ale) threngh afn-i}we en adcens
this mplished eanily wing lecping Comatenct.
S Meat generally wred leopin
_ elemento Joan atey & for loop
_ PK Reading nn elemerde x) ee
L afi)
int 1 y,7=3)
or (sojicemisigt) Ey folie; tems ite)
. oe
TO ~_ aeomg (Gat tabi); ney (Fl kali;
fos is oj ign itt) =For acceraing, on individusl elemenl ef The _
tie dimensional arrag, the array Arubscript t
smut be ured
Exame int afAIEe) 5
“Vo access the I clement ie M4 ree and a column
ateltel, fo eccenthe gM clemed & Are and
at eclumn alelfi], avd Ao on
. iy peneral tp atcens the elemedt in 5 yo and
2 “Colum all (il, whe m uw the 26 number
and 1 & the Column number
To veod and tote all the elemenls im hoo
dimensional army, Q for loops ave veqmired
(meted for loops). Outer for leep gives “the number
see and inmer for leep onvet the number ¢
columns: " _
[To read oman _elemenk x]
dechze igmsigd) gerlice: idem i4t)
— pe et pie jgen-ty pet
= 7 Acorns (Ya, ealiltpD: Acang (ta, —— :
7 Lx To. cliaplany * wenn _elemends im MATRIX for %/
for(izorigrm: Vad _ fori opigem-15i 4+)
sk 2 _
~ felis =o jsmijttd . fexlj=0; jax jj +4)
$e
prinlg Cat Farr aal prin (eal, ALTE):
3
eas) eee _ pink (bswae parallel aricap ) Exploin ih an example
_ the arrays told me the eblen
Aubscripts > a loop are Called ous
“Example. [x Copy elernenh sing oe steg RAL
_als}= an 4s ©, B, 10% 5
= Sar D
An axrex (eqwence)
1 Shing. and ib & fevmimatek k
TA cause 5 literal ip
enclosed by oulde amcte
“the Sine, ne “one
ere: NULL character iTniticligedion: sien: Sti mey Cam be inchabized a follews.
_ ‘Sepectan | Cehas tes: ame [Sx] = Sting Value } ’
Where Sho Value Can be qpeeup ig clotaddias
emdlaved wsithid double qreld: or ete of
_hatadon (Chamets Conbanle) _
_ nets = Ta iret Care mull character is appended coctomnially
Wk he end tring by Ke compiles.
An the Aero Case it iB mecemany arn Ve
wll chanacler explicitly af the end of te thing
org the programme 9g
Exell ze tra Lic] = “¢ Pregesms! 5
TERRE
mELP Ela ae Pehl
“the Sige =f the obove Abma Aki i 10
The length ff te abeve thing anys
Examples: chat Alea nal= pee PL yo gus eds,
A é 1 s 4
- mE TEL ~)a ey
Examples: char ais a2 A
Atespo]='c' 5 Ales[a]=' ahale]="y
Atap = ‘ul; abs [i='o) ats Tiras
ats fJ=*P! “ates [S]= ‘9 Abs [5] ='m';
i_ahabd= 05
Example: char Aby ayers Program
ches ath Tra] sic) Wie, v0 att Va NOES
oes eo. rz-eaays 9 u 7
_ ay Te lal alee
Examples: char as [ic] ='C Pregqram'; || ILLEGAL
Example g: char Ae [a] ="C_ Preagrem! j I ILLEqAL
Bxormpler: char aha L]="xy2"; Examplee: char Abgly-t'x,'y ah
\oWB Bylo be Slaps | invelved hm gt ond Lom tin
’ 2
~____. fing?
| cur ieee pS in the Ahn
LAWL only € & Afeved.
ol 23 45678 9
awl (e fo
Became Beary Ale
character ee cond eta
TK Reading, Shin i) Ok mae
aa tas? re __
gk ARIS; —
oo fic uyer enters ©
_ ating awl _Complele np
2 (2 3 4 5 6 T 8 79
—_ ae Tele fel ale Te se ma
a Shona wane, pene x
Char Atel Pel =" c Pre puTPUT
int Welcome te the ¢ Lub’) Ttoalcome + the C Lert |
oe pong (*: 7s", dtl); 2 Prearam
Welcome te ¢ We
C Preqran
——aee eee
14"8G Explain ang 8 ahing manipulation fanciers
th an exarmple ? &€®) iS
Unl slime rncoupalation Wbiary -pnchione ana
explous hs them isi example?
Some Ff the shime, wramiplehon functions
“Fagin in the dtandend’ Ubrany [abing. hfane ao
Neves :
) Ahlen (44) > Rehom the lenath g the abine ah-
__a) .Atrepyy (cert, Av) ~ Copies Acurce Sting arelts the
dleahmnehion bing clerk
Dabnerg Clea, Axe n) > Copier “my chayacters from
dource Ating areto destination dhing dest
A) ac atx)—> Compares.g Ahimgs abi ond Meo
B)Abenemp (Ab, Abi.) Compares yy characters from
Artima, Abi ith ching ates
6) abriconp (Abt, Abra) — Compares 2 Abimeys Atl and Afra,
bd mot Cae Aenaitive
DAlmicmp (ir, Ahan) —> Compares In! chavactem af Q
Ahinep Abl and Aha, bid not Coa e. tenaitive
__§) atvcedt (Ah Aha) —> Aad ox Oppends oF Concelenales
ating are al the end of dhing abl
4) Atrtet (At, Agqmbel) —> Replaces all_chavactera op aly
tik “the given Agmbel
le) Atenaet (Ate, Aigmbeh 7)? Replaces 'n_charachrs q thing
: Ate ath the given Aymbook
uAtrrev (At) > Reverper the characters iy a gee Arig, Abe
ts) Abncak (ARI, Alea n)—> Appenda iret tn’ characters 7 abng,
Alta ot the end of abing Ath
) Alor (Ah) —> Converts the Abang alt to lowereare,
uy) abups (Ab) —> Comveste the Ahing, Abb Uppertore 7
— ——40-ang The Haas
be folloroa : a _
pone length = Atle (ab):
_ Thi sumehion renee the c heogth the ahing ahi
counts all the character» tpte ‘e"_except yo". Se, ar emph,
aking hao len, th zero
Earle :/% Prreerram to find the leneth of the Sting 3¢/ _
ae isyelude << Stdio-h> _ a $=
a inctude < Shing-hy
aman 0
4
[henge Shing © Preqrem a]
* Rpyidel rc) | Sting ae =
Lia es to tke headea of ate The ageiln &
; “destination eas det
the _aiye =f Aow
__ content of
twee the onginal
aq cest ose lost. ose lostExample: /& Program te ahewo the wage of Ahepy ec]
ok tmelde Cstdio.b>
oh includa < Sting -by _
mes 0)
as
chor Arc[é]="Kssem" }
chon destte] ;
Ateepey (det, ave);
prot ( Destinahon Sting 275) 40k);
3
OUTPUT *
Destination Shine = Kssem |
$
Streak (Sei Sh2) | Shine Conetenation. _
Lite degenek to the ida file ahing. bl The agniax
a _folleves a7
Atresk Csr, Str);
“hia function appends (adle)all the chavacte of
thing At2 te he end fF Ahing ain. a
The nuit character f Anne ahi & seplacect be tha
ferat character of Alina hz. For dope conchncdtion,
athe programmer has te check sahetan “Fhe alge q
atong Abts loge enough b Atore a ating t
_ length tri + tha ¢ NO _ =
Example /x Program +b add hor stings using thet0 x
Finds Cadio-h> 4
Fe iebe Shing
mar \)
_ che ati [se], a2 D8)?
_ponly CEmte the qual a
gear, ;~ pam Enter The second Shin a\n");
ee Gah: —— ao
aired (All, Ate) Fl
7 ; “pring (Conedlanafed Shing = 780 ARD7
estore the foal Shing,
Computerel |
— a | Enter the Aecond Shing
Proqammingel
Conetleneted” Shing = Computerregramming.
Xe Atelwr lsh) * Shine lower _
iThiia degined ty eae ‘pking bi Ths Agnte
ow Folletos / =
: Hihaw Cab); —_—
This ee al he characters of qe thine
__ pty isto Lower cone elunacters. —-
ea x Pog tp Convert “the given Abing into Tower ¢ cove &/
FB indute hothio- ns
+# inebade € String-h> —
main() Z -_
} _
cas ARf2e; —
r : pra Enter ang Seng) =
x ann (Ate)
_ hor (Ab); _
el eonverked Shing
Enter ong Son
Compote; *€
Convete] Sting = computer—F\Nvhet We a -function® Wwilka ic progam te ind te
dere ef a mumbes Kring. Suction’
= A large pregram com be avid inte
wrknagenlle pieces Called redler tobere each module :
. lees \e Apecigic tach. “Thus, the funchor affen called
—medeles ane tely-Contained Arnal prograrrs that Gurney
_ out Adyne Apecizic, well depined Jaaks
_ The are & type of funchens:
ae GO) Lively [Guill] Predegemed punches
Gi) baer Dagirel Ranchers (UDF) [Programme depin A
che
7 Functions thal one loved wycthe librany, ane called
7 library fumehons. Ex i agit 0, pant O, Aeampl) ke.
Funcheos thed See vention bup the wser/P marek
Ho clo some Apecific task & colley user defined -funchens
Ext Arent), pach pial O), ewbe() ete
_ 1x Program to find tbe cube =f a muwenbes sing fonchonr]
— thincde CMdio-h> \ _
ink erbe(iok m5 \
main ()
a = \
int num, vu;
pink CEnter ang eT
Beary (Pat, ker) 5 a ooo
yes = Curbe(num); 7
— poy ( Cube PA = 7-4", num, 5) :
yo _.
int enbeCint ) _ : -
yehon HEN
ourpeT =| Enle any inten |
aea’
Structures avd Unions
Ag
4 4 Ateackee ? explain dhe & Soils Ps Shudure
ton veh on example?
‘Hero chive & diggererd an avy 2 Ex plato
| decay.
deckwation sf a Shuctre any example} 7
ER
What % a Atmechiwe atta Tape? Explain 2
Defone a STRUCTORE? Explain Stuchive vals Spex
aud example ?
_ Shuchwe ua Collechion of related data theme of
“digferect clan hy pet
fn ara is a Cllechion reer af deta
clemerde Atored Beqpertally one aster the ofr io smemery.
The Sepolen f Stnchwe Ws ay -follevos:
7 [ichee abnd oo kegroord
_| tape! members rotvich tells ‘he Compiles. De Toba
| _ type memrber2; ahmchve | & Ee: clegined _
: facrome oo wel ty idee”
| a ee =
i typem membern; “ke abuehre-
EE fegpel. types bypen tole ks
| He deta type in ©) Inclucking anclir __Shohure -
{ smemberl, member 2 am evhber ene the
[members sf the athnchwe
1 as Shucluves Can be declared in ackggerent rou
| ed Sheets
_ Deetiee tithe : :
Gi) “as dletined StruchureJWeaged ects
oo Ihe Atmehire depmition “petodiated us, a a Tag
imame & Called tor Bhenchre-
In the Shrdwre depmihon the Wenger _
lee byte keprord Atmuet & call
4 tne
the fipalan ond example A Tagged Strechve ©
Perr aly | eee
char _addwers [28] 2
int empid ; a
EMPpLeyee a “5 dagname
name, addres, emprd, dala members of the
OP “7 $s
re.| a
(Gd Stuchwe withent deg:
© Tn The ctheehare lepinition the dag rome & ephienad,
ithe Strucure _dlepenition vaithed a “tog mame & calles
ee wiked
—_ The Saget and enomple ff Atrere vibeut a
— 7 Lerss ~.
Sy ah Example 2 Abmet
i
~ typel vert char name Lig]:
eypeR Nor2> char eee Baas
i tot empid
pape Yea; leak olen
a 3 Abwchore -Vaosalle Fempus
sib exemple hew te hee 4 crecte Arndone waing “Raped ?
e ezined “Stonchore
The pete Cape. 2 clefimibon) ki kequerd enables the progamme
ow a nerd data type nome sorcthe wt deta Hype
eS Dat deypedes _exiatin citvtype newdatahype s
__ =, Type int “INTEGER
BaBs
typedeg te dsfine Atmchre types
the Segrtan eee f Fype defined Ahchore 5 <9
fleet Halang + _
Lemp! =f’ Arvada", “Bengaluru”, 10,25 200, 625 7
char namelis]:
char addreu[sc]> = ae
td erp ds aancla's ,
& S
‘Lil expla sits om romp howd ty accom te membem
\ 4 she Shrchyve!
VA Ahvelwre member & generally accesped Wine,
‘1. lt) _eperedey- g ¢
<3 xb an
mi Lov SLAW, emmph exp)
park Salen it SW, empl aalary)12 | Explein ee Concept of Nested Shudits ih on
Sxormole 2 .
A cabencbove that Contalne ancthe, Ahmehve aa
ile onember % Glled a meted Ahriechne.
[Exeen ple! Consider the STUDENT ingoamation like
name, vst ond marks f 3 4
“The marks of 5 avlgule tan be defined in Ke
ahve oe follow ! ~
Shrek Selegect :
; -
me omekLs ~
int maaks> ;
wt ranks 3 2
EP
“New, tke Complele sladek infor motion Combining, ‘
mesme, VEN and amenks of 3° Aebgub con be
“represented Laing a Atmeke ax Aheron below!
hgpedy Ahnek
i
cher name lis);
tet USNy —_
- And —_ marke; : _
: SStupent —_
STUDENT S;
Vaio altine Vesiae S mmembera of the ebove shuchre i"
Com be _accened Sivralealey, te _accen Le members of
«tbe atrahine Selopst, Bhuekee Voriable marke ahold
be Used.
[#10 acon Strdert name, vin & make f & Subyub x7
S.nmame
S. vs
So marks mans — ~
Sorat banca B=
S- marks. marks 3 at|. | dha
13 | Expleso Almchire wil an example?
+
4 f In ¢ lan gusge woe have arr totes and
“ichavacherp: Lt also Aupporls: array gq ahackondl
J Shuchwve Defcoution: if
a | ~
7 tapes aro _
+ chan named:
eae
TT =o Tek omnask; ~
- STUDENT,
+
STUDENT sfid]s ; .
TThe_ingormation of 15 stdend Can be accened at follows:
SliJ-name
S[i}. bon
. sf} smanks
~Beonpl Jk © pregnarn do sead amd diaplers Shdend 4 information
ing onhay of shuelures #/
Wf include <$4Bo HD : _
smato 0
chen namely
het Usui
olmak = aforizesiensitt) :
& ”
prik Center td. Studert lefarl\n', (40)!
Atoae((fs: sh SpA‘, SLilname, . [i], Usn,
|
& SET)- amare): -
3
a prisaty(t Studerd dear aren"), _
aeme\t USN usn\t Markel")
gelize: iene) x
- iS :
pa (Cy sty: ster ay, SEi}- name , SLi}. USN, v
_ sb} marks) 3
y - =
I. - Ghee how a Almebwe variable u parsed ar a
pecan etin te a -fexhion it, on example
Werke a & pregeem hk pee Almchne Vamall ae
nchion ax gurnert 2
A_-function mary 1, be Called poreing ‘the
nmnerrbers the Atmelwve ow ache parame
Fp JAC pee me dumonshale porting, indvides!
Members fe Atmefwre are ce by wing te
+ (cles) oper
omembers Yop the Ahuchse fo'fpinebon’ %) -
oF tenclude ¢ Shbto-h> _ *
fares a . : =| chang,
&
+ Tanain OUTPUT:
7 WL pot pre f2.323 Piece pops ceaaaa]
B Haplay (px. pigs
= i
voiding int g, tot WD :
4 ny (2
prot( the Coordinaty: ff tke pert oe Fd ord tL, a,b);
L a tha tndiiduel member gttae dhuckire b afencton
+ ia_amore tediove oe the mumber of Ahmchire member
os in ereanet. “This disadvantage Cam ‘be overcome xy pening
the tobe A hmebwe. ie —
nocenple 2 J& CP. wm te_dlenors! le, _pemming “the le
Re imikee oa fonclin xf
tl + aaa h>
Sopa c eee a eae
~ Eat we ; _ _
vot gs _
‘3 pens;, __
Veid diaglan (pot)?
nate op ke pork one aed ST\
Te) abe % oo file? Exphio heto the file een and
le clove funehions Shavdled m0), ; q
‘oa y a Al Big $l pee] ond_clove
funchions\ wif erguensch! l
‘What -o rot ? ans amy 2 Fle funchons, wie on
=r
Ke?
: <—
Explain -fepen(> amd -telone() funchors.
Able We a Collechifs of alata abore_om dak.
Ale epen: Opening a file dene Py 4 Gall be the funchon
fopert),tohiely_ aT the operating , the name
tie _efile te be ed | and Vibes the gile tude
be opened for reading inpet) or for variting Cont pt),
si PT eae we Si
_Segnten : Rilepoioter = fopen ( Eplorard. “modd);-
there “Silepeizter a Varcable of of chee PILE ond it
Combainu a pointer to the Ahrewin avreinted ist gle
if the file epena Auecemgully, othersiae it Gonaives NULL
filename. mame fe oe By be epened
mode =. tate accen wnede, Ht imeludet:
"—» Open a fle 4 fos reading
“whe epers a ple for iorting | e
_ ats Sper 4 fle fer appellin
Fra FILE Kefps KZ, Hippy oe
- __fpl= fopenl' Shadert- tat’ '0)s _
foe Tee opin (‘Student tx txt "1"; = —_
_ fphz fopem. ('Studed tet", “0D;classmate
ote.
15. [Lohat are Sely regetienbial Shuetaves? Horo te
[deme a mede im Clan 2
A Selp reerential ~ Shuchye ia a Shudure
lishich has at least one fod which Ga pointer
Ito Aame abuclure
Examplil! Consider. the -follersin Ahucure depimition.
| dAbuet mode 7
! §
| ink ingo:
Atak rede xlink;
| gi
[obra iyo ib an inten pret hich Containe
the impormakion. ~ :
link & a potmley feld oud Vemee i} ahoold
contain jhe addres. It normall conlan<
the addres of the mext node isthe let.
i 1% Stucke depnition for a nede x] -
| Abuck mede_ _
| Lt
| ink Ingo s
Abud mede xlinks
&:
| Agpedeg Atret nede “3NODE: -
= A pointer Yerable feret Con be declared as follows:
| Nepe frat
| oR
{ Abud nede x feral: 7
ote || Both the dleclavahorns ane tame, Aince Nebe and
Tabud nede %
veid main
L
eal. Union
bee
inf “marks ;
char grade:
look } evcentare |
BSTUDENT g
STUDENT S>
sameck = 100
prin ("Masks = -/I\n" S-marks);
S: erode -'A';
prin (“Grade = 1-¢\n", 5. grade):
S. percentage = 49-99)
prink U Perterbace =/--24', S.peveentase):
; , d $ f d
ovuTpor:
Macksclassmate
ete.
Page
16.4)|Lohot is the dizperence behoeen Stodure and Union?
| Structure Union
4. || The. ketpsorel Atrud & wed [L.Tthe keepeord Union & ured
He Aegine a Ahuehive _ [te clefine a terion
[LOHR a variable & ancinted la Lohen a Variable ae
ae dum f alge gis member. |
y each
lis eyecder than & equal ty |
tall mof_atgect ether members
sith a Abuchive,the Compiler |
lallocedes the meme: :
[member Tthe Aizeg Ahucuye | '
Altering the value of am
Lsith a union, the Compiles
allocates the meme: be
Considering the 4iz¢ of the
largest member. $e, Ane
Jj unien 6b eopwl te He sige
‘ef lergedt memba.
| of lenges meen -
is. Allerine the. value
Ff the member ral) Shes
| ef the abuchwe
The addrese 4 cach a
[sill Ioe in ancendin
lordicetes thet memory fer
each rember sill stark at
oxder "This |
ther member Values.
The addvens Bowne for
all the membemm of a union.
[This indieakes thet eve’
member begin at eae!
Apperert ofpret values
_ y ero. aa _
B.|Tmcevidual members Con be 6. Only one member or _
acceased ak ang time dice be accened at a dime
a eparate memory & vearerved dine meme:
_[Hor each rmembar.
by. each member -Pointers pee
| 17. Tigi aap tipday ou Ie pe senile
H bye
A__peinter is a vale talidh hells the the
| addvene 4 amother Vatialle-
“The pointes eens ng he
~fillewing_cipolon
—— 2 Kk Vaniablename;
tte detahype —» Basic or —watadipined ‘defolrpa.
a
[ ind Vi bes a eF Vasuialole.
| Notiatlename =v 3 c idenbien
Example: tek 4 +
dur b; : i
| ___fleet wes _.
____Ahoet STUDENT X83
) L& inte “9 Vasial
Lint eps Le peiatet Vedic =
_ p=kay /x oddven sf a 22a emed to p xs|
13. 2 Whed is 5 frikes? Si se tase adv: salaye ond [
leak
~ Stat we a eS: tahich heles the
ales a amdhes Votwolh.
- (Advantages:
i ‘ty Porerters provide, “direct _accen te rmemeng-
2) Pointers provide 4a te_xebon eo than
ene value. from the fumchion. Basadel|
> Reducer the” tee dp and _Complaxty ¢ |
. 25> Potater alloros ua te Am! en eme’
° allecalion amd = pf on a
8 Peimbens wath build Complex deta sbrelurer |
ike Linked " Link, 5 tack quenea,trece, re |
a Bieedventnge
es Vare Alowes than normal Variable
oo > Sncnied pen ft a gp
—_—— _ alloted block needs te be
- foo all Cthesisiae, it welds ead to
Dy poibslera ave pdebe seth ine neotrect Values,
at ig jon
: = —_ |diedoy,
2 errr. ‘ i 2 -
Pointers can also be aie de atore “the odddlvers
Oj ebro, Conder an ethos Yat tabich held 5
l deere int_a[5] = £5. leis d025h
dt wes be slered tr the memory of
at) att at) ate) td
fd lo 1S. 20 | 28
4000 V0) leon. Te08 Veoh Toes Toe TT we Teag -
_ The Atashng oddbrein of the above arhay & $000 1 is
aleo called na thas addveny’ ofthe estoy. fox Whe above
Db heee, pointer Can be Created ar Ahoren belero:
at MPL ——
[ ps £alel; Ideexioen adsrers Gopexst element
—- ~&
=a! heen, base adver ic oddren Sook elemmud
(ite ste eet is i sided p tooele be,
_ Vion the value f000__ p_tsill lee poe
LC heen afte ao eee tg
—s Atatern = (ato),!
aleo - sede gen the
eee te the _peintes P.-
__ Jo access the fern: a) enay Uae. =
ee ciser, the. folle edina Alatermiet Can be. wed’
Ty (atid. TT Bequivaled ali]
- os ats] a 5,10, 16,10,26}3 it sumo:
ink XP; o ee —
porate); Ch) pa; (om) p= (ate
ROLig@ ith)
_aum = =Aum + FPS
ptslp mic Memory Management fanchions J
20° bOI 10. mnie rnemerg allecohon! Write amd
i oat
‘c memon, alleechon *
. the disrevent 10am me!
_ jens aoa in ¢° ave as Follows:
UW) amallee)
7 (i)_callee Ofer alleedion
(i) veallee CJ
(i) free O_—* for deallocdion
. } mallee | memreng allocation.
= “Thie_cfunch'en ie ured tte _alleeste “tn omemeny
dusting the tun tome. The pustehype fox “Ibi
. . jem ib available in < shh b-h> and and /o
TF ablgy_ God + (ORLFIDHX2 = FOV > Lo
afij] = 4o9ot C/¥2 Fo) ¥2 = 7094 > 30
aLIL] = 909° + CK2 HID ¥2 = 9096 > Ho
4D) fe] = F090 + (2K2 to) ¥2 =9098 +50
aL] = Jodo + Ox2 +42 =9100 ae
Column Mayor Order Im a bev aimensional wt
p the elements are ttered i Column. mie fockion,
Hhes it ia Called Column- major order
E ampll: Consider an ame al2JE31 in sed to Store i> tay)
Values 10,20, 20,40, 50 ond Go. The. Tepresentahon of
array in memory ia Ahown below
¢ -
| Oo?) 2 ore qoiz gn gore goad, ato?
a oer Sel a [io [go] 3° ]4o |go | 60
2 [eo | Ele) CIC) CAL] LIC] [oI] Cow
Jn_colurm-enajer order the addrens & Coleuloled a2 floss.
__lladdren ofa i = bare ven + (Column imdex %
2 total number gF polos 200 Imdlex)
es __t Ayes eleriert a
Séhen
ladder afel[e] = Jogo (ox2to)¥2 = 9090 s10 |
aI] = 9o90 +(OX2Z+IDKDA = 9092 > 20
g LIL] = 9090 + (1 #2 +O) * 2 4094 30
ali] = Jogo #Cix24+¥2 = 9096 +40
Qleltz] = 9090 +(2%2 +0) %2 = 9°98 750
al]p) = 9090 + (2%¥2+D*2 = Aloo 7 60
22!
LOith Auitable example, explain Slerremie_ cme
allocation for avrauys ? ee
che arres Com be degnamicalle alloceded wasing
malloc, callee ov sealloc funchors Similar Ly the
Nocabed maemomy Cam be “freed olen the. wd Ff Abhaays
HE jovctude < Conio-h>
He imebude
eid may
£
| ink i ij BB
fk tum = 0) chreer 0; __
__prink ( “ember the suber f element
Atoms (hal £9); _classmate.
prnk (Imausycciint Memeny\"');
exit(o); a
4
prin (‘Ember -fel_ element |n'. ‘m))
flies bien pitt)
Atom Uta’, (atid);
Aum + = # (a+);
3
prink (Sam = Lal, Aum);
ee (4);
|
i
Dia Meroory Allocation for Tsp i spepach ey
-hee ee ee
int alas;
CI OIb) ta wW
a tel Lyre TT {
aw | +~—a_L I _]
aw | + TL | |
Figure : Arve of oxrega Yeprenentahien.
Exarnplala :/ Pree earn to_illuateake. algmarnie menor allocation
for I disc clienensional array
leg: 2 MAX 400
He jon clude ¢ Stdio. by
Hb indude a
Lb include Club A>
Beid main UV :
sémnk_i,j ret, Col, Court |
ut xa Liaxd;
Cournt= 0}
praake (Dynami Memory Allocation fu 2D Arras \n: |
s Enter btal number g wows 2") |
(LA, dew);
dP
casa
pant C Enter | ("Enter total umber of columns"); |
A
_L* ie
(4.48 & Col):
4 Allecdhion for 2b Arsay xl
gorlisz eri ven) i+t) .
£
QLD = (mt x) malloc Cool * aye (itd);
3
x Storing Values to 2d Array */
for(i =o; i < veto, i ++)
ij
&
for (jze; j 5
expen! © t 2 eae
ley se Array repraental on f eto <—_t
Caray Storetures) 3fy add An0_po ipovel= aad b
laid pada Cink —asioatA pink piovishA, wt atookB,
[Waite function
3 zeavitant polararormial? |
coat ae MAX-TERMS 1oO
4
pestpne compare (xg) C(O) =3 (4) 20: (0 > (4) |
DeteeW
vit toniahB, unt % stootd, wh Afinohd), |
lveid_ attach (float coeppcuint, ik expon eed):
void readpely Lint aalant, ind eed) 5
lovid__printpol (ik Artest, ot edd
ap
flock cog 5
IRPOLYNOMIAL ;
I$
wt “xpon 3
Int avail = ©;
eid main U
POLYNomMmL _p[Max_TERMS] | _
cnt atest, Atartb, ateatD: |
wot oudA, eudd, end; i
(‘Enter the pevat_y pokmnomiak <
hreakipola, (katanth, reds)!
aintt("Enfer-the Accond _p elem OSD cL
Freadpol(& Ataat®, 4 cud)
podd (starts adh, stoot8 a ‘L&tartD, £endd)>
P ip Con of sep pen mi als\o");
printpely sent.Qe
[v0
|Cefunchon to odd os p repent
id_podd Cut stastA
sick _piinich Bunk xateokd Ae oom
§
toetpety
pAdaohD = avail:
__tohile (ated b- expo */
attach (pLAteskt]: Coa, pleted]. a
ast aah (scjgond plAtesha}-erpen),
adtach(platnall- cox, pleat]: -
Atasta ++}
5
J _ a
J Add the remetrine terms at!
for; adaté <=pémishA “atast A ++)
aitach(platestAl- coef pLatantal- expe;
for jAtadb<=firishBS ataste +4")
attach (platata]-coy, platente] expe
lis
Ffimahd = owanl= 15
AD
oe eee ce remsaining etme of bX]ae
L% Finnrchion te odd a mero term aha 7
Urid_odtach (flood Coeppictert, ink expenet)
Pat (2:
q
plavoul]. expen = exponet;
avalt++;
4 —_
[Lefunchion to read 2 polmom
usid seadpo leg Cust xAtot ct oad)
g
L048 a nero term to the. pelepromiah
iploveil = MAX TERMS)
pan CT Teo amcor tera inthe poliyn omialta'):
plavaill cou = cooppiccat;
|
ink e&xpon ;
feat Corp 3
nee
x Atash = ayail}
=o;
4o1( 3 3)
ia
peek “Term number pale ++);
_ print” Co (ocak 1");
Acom(' Ap", & wep);
iGeg == Brak;
Ponbt Exper a
(: 1a & =e
cltach (coq. expen) 5 —
3
end =aval-l)eS
omial */
[x 3 0
i ’ Db stork “uit end)
rAole (Abert < ad)
§
pankls-s2¢x nd", plstasd]- coop,
plated] expen) 5
Biaktt+s _ _
i (Pl atest]: coy < o)
pact (14", plata]. cose) »
&
prnty[ + fd * pL ated]. Cog);
4
poink 52g xc)", p[ Ateot]. Cog
pLateat]- expen);
4SVY
ree mabtix? Give the» epmecicie
Spe crnadtin wing cthchineaT Gye ; 4
had Vere pero MON -34.0 het dpread at Sock
q
[Henly “The remeasoui' checels of te, malsin
ancbiix sith
lane “Commderedt Lo
[frs_men-zto ele Se wore suumbey of
yeron) b Called paras Matix.
[the Apavae. amateix Con be Aingle chiamenaiencl
anulhiakonem! onal Auch a2 2 eae exrsional |
ove. Elena ee aud Ao on oT
lh: Single chen ervey onal amakai cer
!
|
|
a |l'eol ele]o ]20 eo} Sparre. mehr |
eo 12°32 4 § , |
_ | b& [te To Jee] o ]20 [ae] Nota Sparae mleix i
leet ae tee :
1
Examplz- Trsv-chenensienal makices i
| fear sy] 5 eo eo -e T
6 82 2 Oo YN 3 0 9 of}
Ae 7 ~64 i} B=[0 0 0 -6 o of
= 84 oo © o© 9 of
27 ie at 47 Hie 9 0 7 Oo}
| wet a Spare Macs’ [o_o 28 0 a
| = _ Spav okie _
SS
iverm; ee
1k _ ae ————
arae. Morten R present hon _ =
He define MAX_TERMS 101 _ _
raped Fe
a Rte oat aT TET
[Term a[Max- TERMS]; 46Repteaerntation wpe. Triples tin a
Single Diroemai onal ovney o __
(
lo © Oo 40 i
A= a} oO 2ru oo |
oo 0 © 4
20 0 (Caan 10) - 4
Oma! SeusOnm2 of : }
Spare Matin Atored ap Toiples |
ew Gl Value
Ale]. 6 4 8 +
Ata o 2 10 : i
Aly © S40 _ 5
A Bl { o 1 |
Af) |
ats] 3 ° sai i
Ale] 3 3 ~50 _ _
at 4 i 15 a |
Wish 4 3 25 :
Tracie ef Spee Malis zlurtd en Triplet
| 78) | Voline :
[eo] 4 5 g =
BL) oo eo 10
pf) © I! Me _ _
2 (3) } 20
pf] \ 4 15 =
bis) 2 J =
Bf] 3 fe) 40 _ —
si7) 3 3 -50 =
af[e] 3 4 25 -
lo i) 0 20 ©
Be |O o o © -I5
Dm omr Ole 0
4A ° oO oO 750 25 5 _
AT2.6 Ik). 5 O c Ae
coe x value, ensch the. _t
| x for 2 Aer.
Par. eo
on inle. < ret, Column, value? ty represct
em to the Aparae. omeatnin.
Hdepne MAX-TERMS 101
Hh include
- Sterm ; ;
eid aman 0)
§
Term _alMax.terms] :
=|
Ht include _
th imelude< bhiane
Void pedamateh Cobos apt, cba str);
oid mam U
§ ela ab fod), pet fies
OF
i ie 4 + Shime
tr);
pat Enler aony deaching pathes ¢
eth Gel abl Ae
od. pet mates Cebar epek ches x Sh)
5
ied iy Alen plen, Count = 0}
len = shlen 4k);
gor liz ori<=dlen plemt 1 re)
_ |
plen= Atvlen (pet):
4 I
for aos yc ples; ytd)
4
| i poh Liaj] t= palyD
| “break:
5
tf Cj== plen)
Cow t+)
3
yh Coourt == 0).
Ph Search Onenccespt
oy am face’ \de
|
r - erase tanie ‘lave. ‘o e
4oll i f term 2
L@) aaaa bo
lb) ababaa
WW abaashb aah.
2 Coomopaching the. a ganchien 2/ A
a \
1
{
Cornet the pattems teilure tun con x1
wat ap jen (pest): :
fas lune Le] = -15 - =
v(jeytyzens =
fe Ga} jt
= faslone C1]: 4
shale ((ped Gj) 1 =pt Li ri) «* Cz =0)) _
3
i= foobar Ws |
paar _ . |
ip Grad C33 == pat i+)
: nlure CJ = by _
else
feiluon Cj) = ="; =
3
3 _
|
fa) -1 Oo 12 =I - — So
Ae 2
ON) at trated ae Ono stybdaite a japetion ine te caentpae a piven
i
al stronmpose (Term ald Teem bl)
§
ae et te
iat ,., Crrreth '
n= ard. value :Attotal y_cf element */
bl ol. ve = aLe]-cAl 5 /¢ cows in b= Columns ip a %/
blo]. cet = a[e]-0t0; /wColumna in _b = ree In a x/
blo]. Value =
i, a>0)
§
1% men- Zs Se HI
Corrrot b= 1)
roe i
He Imcliade < Minh 7 }
. g
Ueid mam VU
£ '
han Abfioo]
(mt ¢20, Cound 24] =jo}>
priest (" Ender Shine, \n')
pibGsh): Z
Mele Cabte) $= "\0
{
X Conmdeins characu from a te 4 why x/
7 if (ab [e] pata’ aR Ab le] <='y)
Count [Abe] = 'a']++ 5
ctt
jo
for (cao; cere: ett)
i
# Poioting only these charade where Count
ob olenst 1 x / {
ip (Count [e] {>o) j
pret (he occur shea Hes in the ;
al entered Airing vv" cra) com ED,
53