0 ratings0% found this document useful (0 votes) 37 views13 pagesArrays - Class 1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
classmate
* ‘tg) Pate
lo/O2 (2023 ss
})
Axrat
A_bagqage which contains only similax ty be
of} - 5X4 = &ov bytes.
e odues Gh aniay axe stored ak conbigueus
loy U2 re [77 Memory
LT TUT
log M6 124
Why. Is_ownay needed ?
One abblicah'en « n Mike (f we
find the maximum: “This wilt
fasten eshte Cine
g— This 1s ones} the app licabien s+
yy tena aurora aiken applications ‘an —|
Wet:
vvuaiicu wiur vdM| int ann Clooos>
—
The above ne 1s the syntax Sh Creat; _
On asap e,. looe inkeg B this we!
have vesenveck Space for lOoctnkegens.
[-_— allocahon ? (Internal fragmentabien._tn_ of
Is these memory wastage In_Case_s4, con} fn
Int anx Clo]; ~ +Xlo = to bybes
| |
(24 byte 16 byte
Total memory avartable = 24 +}<¢ =Yo byte
——_|bur it is not continvous wb is dis Cuete 2
hence we cant make the aniay ef Ic 1
rake Hence tvs Is memory wastage.
Creaking an aniag
1 vouable nan
int _anx Clod3
f © size of osu a
doka ty be SG a
The square bracket: ts a a
Fe Avis. the p (Gh Syntax
We have nou Rnown. the declaxahen hast —
pf omuny As how te. declase the anna —
Fixst adds ¢honray (¢ alse known od
tthe: base addruys -
Dvaimicu winrcam|
classmate
int oso C7 5 S
cout << ann << ends Both gives Same
cour << Lam <. En thy rest
ot S voli widt be O-
Biron 2C4)= £2746 951235 3 Tis wrbe
Give On enon as we have hu ove no-64
elements than the fntttalrred Size.
-——_]AQ0 the above asia ‘ Ie
dyson. Stabe annoys fe
—— Vgc asimays | en QHe Ayanami _axnays
Which Wwe wilt cover Sater
_Xotell > int 3 7 This wil? yun en seme
Cin >>n» 7 compiles. but thi 1s
Int ann (nJs J a bod produce an Anos
ts a lim te Stowe
Clements +
ovaiiicu wiul vainFo) BO, 40) sos
Tint ann (s3= {1
The antay ele ements cna acctnsed With 2
help of “Indexes
lo index
20 Ist fndex ann
Bo 2nd index
40 3rd index
So 4th Mndex
Sn O = based indexing _1s_done.—
SF oun ommay — Slats n_»—then index
rh Ot bie trem 0 tern-l Cb > te n=l (both. fnclusive)
> lo ts the Output _
couk << atm [ol] >
Formulas
conibie 4 of Dh index (Base addours +
gah index * Sige ef dab
[oJ 7 Out OX4+ = an 7 This—
means thot give the value eae] ——
Advts ann which IS the base addnors + Hest
Vv eae : ——«
lann [1] + ane +
+
Imeans the next memory fo “
hence So Lhe prea eeh
ip Brake the sy al ig fo lp —
ee eeittiog “ana Toa fi Orn (1) -~ asl
————————vanicu wrrefamclassmate
We use for oop in_pyint ng —oxnay valhees:— $$
for (int ve03 ve Ss c+rt
YS
DILSDSLDD SLE
|
5 Couk << ann (tJ <<“
Output
Js Ss
lo 20 30 40 50
/
|
Int aux (lols
”
/
cout << “Enter Input value in asmay "> anx CLJ5
3
— Quat Take 5 elements put tn_arary and ____.
pocint ther chou bes
| Anal int ann C535 7
jae couk << “Enter aunay values” <> Qu Ct35 7 Tabing i/p fn anna
3
for (int =05 t< 55 tte) i
cout << 2 * ann Cr) << 3
3 Printing double of
ach Number J axsay Valin:
U
Quih2 Change att the annoy vaolurs te 1:
Trt Ws. 2 fb 3,4, 543
—An Fow (int U=O3L<5 5 c++)f
ann (t) = | 5
3
——_—_—_—re NWN CSTE WITT
man”
~
XY
for Cink = Tepi 1e 53 batt Dp
couk << Ut co sé ca
_————___| oe
3 ——
——___Ouxput a
| ee ee SS
ote ll() ink on (lod; 7 Toinobliged with anboue vy “a
) intonn (lol = {045 PAU valor as ina —
wrth O-+
Inihates, ng OHH with O paxtoulon valu
We Use ee net
Strays and. fu uechons
n_pass by value Concept 5 copy 1 creaked L
le.
io imborkans_4 te:
eu
> note that when
fat paused im Buchan a ten
pect ace fet
Kop This concap—
IS known Ob hors by yeferena.
We have te fol
a
We f ove—afrachica that wheneu
\ winston then we need
Sunchion- te
E204
Void incr (int ans C7 »int <
5 aes aa
vuaiicu wiul vamclassmate.
int maim () £
int ann (SI = {1,2, 3, 4,535
Cour << ath Cold << endl!
Incr Carn, 5) 5
cout << awn Co) << endh5
xetunn 0}
Dukput
a FRdual say is Updated .
Notes|[Para by yeference means that the address |
passed & hence a seperate copy Is _not created -_
Why size te E passed ateng with ons in
unchions ?
Onn [lod ="£121345 ;
size of Card = 4o =lo but nod
SVR Of Casxn fo) 4
elements in the annoy three 5 that/s why
w e need te pas the Size explict bly ______
Linear Seaxch fn Array. _
fpraun C J =£2,9.6,7,4 I Is35
We need te find whethen 6 IS present tn
Ox or not ? -
Ww each index & See Whether th Js
¢ oy not Fi
a Yel
5£ not, move te next index 4vebeat
(i) SF present » then tenmrnat: Search.
FTexrunat. Scanch if oth the oma elements UL
err WITT OAMchecked — ——$
Code
in size int
| bec Findélement (ink an © »-IDE Stet nth 4
5 cat) {
en ew Bacto cee
Cj == rey) i
if Cann
yetunn truss
=" al
3
yetuin fatae 37 IF not found even aft
5 Prayers ing whole csixay
Qusrd
Cunt Os ond -Ls_tn-axhay 4
ay 2 fF element is__
Just traverse the on
Zeno sthen do zenoGunk ++ LF cunnenk
lelement Is one , then do one Count ++5
Code
int own (S3= {1,0,0,1,045
Int zexo Count =o 5
Int one Count =63 ms
For Cnt v= 03 tess Vet) f
IF Cann (Cl == 0)
Zero Count 44°
else + As oun artay only have 6 LI
Ohe Counk + +5
SC IIcU willl CaMclassmate
Qu Find maximum number _in_ the avon
}Coud_<< “No. of zeroes are” < max) f
maxt = ann Cis
3
Couk << “Maximum number is ”< ax cc) f
mine = an (cys —
3 —
. y nol
out << “Minimum oumbex Is” << ming:
Qursf Coctreme by L aoa
int ou ($3= {15 2, 3, 4, 533
O/p> | 5 2 + 3
This is Guishien st 2 pointes, approach
Hee take pboinken as yarwable:
L 2 3 4 s
Bs
Stasve ~en
1) [Print ann (stant) , ann [end )- _
Stank ++ 5 end-~ =
£ = 3 + S
7
&
Stove end 24
2) _ Pink. . ann [stant] 9Onn Lendl —
6 +, end-~ :
ovanneu win Cami 2 3 4. 5
cae
Stone end
Now it gets byinted twice Tust pur o
conditien Sf Start == end, then print onc:
We have te Stob when stort qo beyond
lend-
Code
Int aun ($J= €1,2,3, 4,833
Int stant =O.+ 4m Z
ink end = 42
While (stasce <= end) t
if (stask == end) £ —
cout << aun CstaxtJ << 775
break 5
5 : — —
cout << arn [Start] <2 05
cout << axh Cend] << “© 75
Staxk +4+5
end--2
3 -
Quel Reverse an anna
£263.4, 545
int ann CS) *
ospy 15.4.3, 22135 _
This can he done via 2 pointer approach.
by reploeng Ov (stant) & ann Cend) &
abate aanhe as_cxtreme _pyinks: Extreme
ped & hence we get the
vvuaimicu wiur vdMreyenns 00g
ee ee ee
L 2
Pz
Ss
Swap wv fs] & am feJ
S++ 5e--
5 2 3 4
7 €
S en
Swab ann CsI & onn Le] a
++ ,e-- ——
IS 4+ 3 2: ae
AX a
s € i
Swab own (SI & anne) ”
S++, e-~
5 4 3 2 TT
Z r 7
£ s =
S>e 4 ext rhe loop _-.
O/b+ Revense of the inpuk asanoy is what
ok
rg 7
int awn (S22 4123, 4,555 a
Int s = 0) _/
inte= 4)
vuaimicu wiur vamclassmate
while (se ,
.
Scanned with Cam