Professional Documents
Culture Documents
Array 2 Annotated
Array 2 Annotated
ARRAY-2
Lecture-12
Raghav Garg
Today’s checklist
3) Vectors in C++
4) Operations on Vector
5) Problem on arrays and Two pointers
ereference
Passing Array to Functions
I
142746
24
I
an
as h
o
MCQ : When you pass an array as an argument to a
function, what actually gets passed?
int = x
- int* ptr=&m v
int* ptr= arr;2
;
int4ptr x; X
=
X
Arrays and Pointers
an
x48xs
ee
8
# 52
x x56
Y
60
W
x
0
pty
output
-
700
x
426 17
Vector in C++ ->
Dynamic Array
↓
vectors int> arr;
array
hi
replacement
I
problem -
fixed size arrt51s
int arr[S] =
31,2,3,4,53;
y5/6/1)
11 I
(192,3,4,5,63;
Basic Operations on Vectors
·
Syntax
-
capacity,
w
size, at, sort
·
push-back, pop-back,
-
⑨
Basic Operations on Vectors
Output
I
9 10 x
I
6.1
6 a
10 10Garbage
assing tors to Endions:Diff. to
Arrays
is created.
& ->
amper cant
Looping in vector index
A
V 13 2 Y 34 16
* I 2 34S 67
X 1
=
intidx =
-11; 16
Ques : Find the doublet in the Array whose sum is
equal to the given value x. (LeetCode 1) (Two Sum)
-
V 13 2 Y 34 16
I 2 34 56 I
x I
=
10,7)
targets,
[3,4)
(4,5)
(6,7)
I
~
~
v Ea
X
Enter target:7
-
8
-
~ W 8
Enter
away size:
v.sizel) Enter
away elements:
=
- 9
- I 3243416
-
I
·
(0,7)
·
(1,3)
·
(1,5)
0
vitili
i
j
Ques : Write a program to copy the contents of one
array into another in the reverse order.
V 13 2 4 3 Y I 6
it j size-1
=
" I 2 3456 I
v2 6 I Y 3 4 2 3 1
↑
* I 2 3 4S 6 I
F
01 6
V 6 I Y 3 423
j i
int i 0; =
intj v.sizel)-1;
=
is
j
=
Re barraway
⑧ I 2 3 4 S
arr 16 2 37 Y
CIm
wer(4): 1
= 326
73264
⑧ I 2345
j i
Ques : Rotate the given array ‘a’ by k steps, where k is
non-negative.
Note : k can be greater than n as well where n is the
size of array ‘a’.
⑮
awr
16 2 3 7
Y
2
C 741623
S
⑧
I -1,
& -
Y I
- &
I &
I
3
2
Agithm:Hintereverse partof away
visizel) -
1
-
⑧ I 2 3 Y S 6
I 6 2 3 7 Y 8 k2
are
=
- -
↓ k kd
n -
26 I 8 Y
-
t
816 23 7
-> Y
6237 8 k9
=
I y
48 I 6 23 7
if (k n) same
if (k >
n)
=
-
away is
R K% n
=
Iwork:Leetlode Array
THANK YOU