1
00:00:01,940 --> 00:00:02,540
Hi everyone.

2
00:00:02,540 --> 00:00:06,770
So in this session we are going to learn something which is called victors.

3
00:00:06,770 --> 00:00:11,400
So if you remember the oboe section so in loops with color no problem.

4
00:00:11,420 --> 00:00:15,370
We implemented a glass and then all the glass was dynamic added glass.

5
00:00:15,380 --> 00:00:16,490
Now what is a.

6
00:00:16,640 --> 00:00:23,960
So that is basically inbuilt dynamic getting so whenever we have a feeling that I want to use that dynamic

7
00:00:23,970 --> 00:00:30,040
Eddie what we will use we will use vector because it does invert it is provided by C++ so it isn't built

8
00:00:30,050 --> 00:00:33,040
and we can directly use vectors.

9
00:00:33,050 --> 00:00:35,080
Now what does that mean to properties of vector.

10
00:00:35,750 --> 00:00:40,910
So just like the dynamic any glass that is exactly same as dynamic any glass or what will happen.

11
00:00:40,910 --> 00:00:46,550
So the first minute properties basically you do not have to give the size of the vector add friend you

12
00:00:46,550 --> 00:00:47,760
do not have to give.

13
00:00:47,780 --> 00:00:49,850
So if you are creating an eddy.

14
00:00:50,090 --> 00:00:55,630
How do we create an edit V right in a and then we will give the sides for example the scientist in mark

15
00:00:55,640 --> 00:00:56,810
for creating the vector.

16
00:00:56,810 --> 00:00:58,120
You do not have to give size.

17
00:00:58,970 --> 00:01:01,930
So that is the main benefit of the vector.

18
00:01:01,960 --> 00:01:03,380
There is no need to give size.

19
00:01:03,530 --> 00:01:08,360
And the second benefit of using vector or whatever it is is basically you can insert as much number

20
00:01:08,360 --> 00:01:09,440
of elements as you want.

21
00:01:10,560 --> 00:01:12,890
If we consider the array you cannot push.

22
00:01:12,930 --> 00:01:15,030
You cannot insert more than 10 elements.

23
00:01:15,030 --> 00:01:21,600
You cannot insert eleven elements inside this area but if you are using vector since the event is dynamic.

24
00:01:22,560 --> 00:01:23,620
So what will happen.

25
00:01:23,730 --> 00:01:25,740
We all know the property of that base.

26
00:01:25,740 --> 00:01:31,990
Basically it will double the size of entities food so for example if the event plays initially of size

27
00:01:31,990 --> 00:01:35,140
to if you will push the two elements.

28
00:01:35,140 --> 00:01:39,320
Basically the vector is field then what will happen that will double in size.

29
00:01:39,320 --> 00:01:44,300
So now the current size of the vector is basically four and you can insert the elements here.

30
00:01:44,300 --> 00:01:50,580
Similarly if this compute that base is filled then what will happen vector will again depoliticize it.

31
00:01:50,600 --> 00:01:56,120
So the size will become it if this factory is full then the size will become 16.

32
00:01:56,210 --> 00:02:01,070
So effectively keep doubling its size and basically you can insert as much number of elements as you

33
00:02:01,070 --> 00:02:04,550
want but with Daddy.

34
00:02:04,670 --> 00:02:10,760
Once you give the size you cannot insert more than 10 elements in this case but with vector you can

35
00:02:10,760 --> 00:02:13,220
insert as much number of elements as you want.

36
00:02:13,220 --> 00:02:18,830
And initially you do not have to give any size to career development to these other main properties

37
00:02:18,850 --> 00:02:20,810
why we use vector.

38
00:02:20,810 --> 00:02:22,610
So now let's see that in action.

39
00:02:22,640 --> 00:02:33,420
Let us see how we can use vector so first let us let's see how do we create a vector so I have to write

40
00:02:33,420 --> 00:02:39,230
the keyword vector so I will write vector Victor V.

41
00:02:39,520 --> 00:02:41,740
So is this right or wrong this is wrong why.

42
00:02:41,780 --> 00:02:44,690
Because vector is implemented using templates.

43
00:02:44,690 --> 00:02:47,060
So basically you have to give that in a type also.

44
00:02:47,600 --> 00:02:54,230
So I want to create that proof in integers so you have to write what you want to store in your vector.

45
00:02:54,260 --> 00:02:58,700
I want to store integer so you have to give in Peterhead now.

46
00:02:58,760 --> 00:03:01,640
As discussed many times there are two ways to create work.

47
00:03:01,700 --> 00:03:08,190
One is using the static a location and the other one is basically dynamic integration so that I see

48
00:03:08,190 --> 00:03:13,660
this index for creating vector dynamically so start VB vector pointer.

49
00:03:13,680 --> 00:03:21,160
This is new keyword then vector in tejas and this syntax.

50
00:03:21,350 --> 00:03:31,080
So this is actually dynamic and this one is actually static and we all know the difference between the

51
00:03:31,080 --> 00:03:36,030
starting and the dynamic dynamic means we have to dilute it ourself.

52
00:03:36,030 --> 00:03:42,720
It will not be deleted automatically we have to delete this vector but if we are looking static memory

53
00:03:42,750 --> 00:03:46,580
then what will happen so this vector will get deleted automatically.

54
00:03:46,740 --> 00:03:48,890
Once it will reach out of scope.

55
00:03:49,080 --> 00:03:50,120
Simple.

56
00:03:50,160 --> 00:03:54,320
So now let's see how we can insert the elements inside the vector.

57
00:03:54,480 --> 00:03:58,930
So for inserting the elements inside the vector we have a function pushback.

58
00:03:59,100 --> 00:04:06,790
So we start pushing back and let's say I want to insert certain so the suggest what is the use of pushback.

59
00:04:06,810 --> 00:04:13,900
So suppose this is my vector no pushback means as the name suggests I will push the element at the last.

60
00:04:13,920 --> 00:04:18,890
So Ben will be pushed at the last but since at this point of time my back is empty.

61
00:04:18,960 --> 00:04:24,150
So Ben will be pushed out different because the vector is empty but if we will push more elements for

62
00:04:24,150 --> 00:04:27,630
example you will push quanta and then you will push too hard.

63
00:04:27,690 --> 00:04:28,570
Then what will happen.

64
00:04:29,240 --> 00:04:31,310
So first they will be pushed.

65
00:04:31,650 --> 00:04:33,130
Then they will be pushed.

66
00:04:33,180 --> 00:04:37,690
So this will be the state of the vector 10 20 and then 30.

67
00:04:37,710 --> 00:04:40,850
Okay so let's see pushback function in action.

68
00:04:40,890 --> 00:04:43,450
So let us push more elements.

69
00:04:43,470 --> 00:04:49,290
So let us copy this and we do not have to worry about size.

70
00:04:49,420 --> 00:04:55,260
If the vector gets filled it size will become double to push as much a number of elements as you want

71
00:04:56,670 --> 00:05:02,380
so currently the size of my VAT is basically three disk containing three elements.

72
00:05:02,510 --> 00:05:04,350
Now how do accessed those elements.

73
00:05:05,210 --> 00:05:06,500
So we have square brackets.

74
00:05:06,530 --> 00:05:14,640
So just like in every we can access the elements of the vector using this credit brackets so let us

75
00:05:14,640 --> 00:05:17,760
copy this and let us access the elements

76
00:05:22,540 --> 00:05:24,270
visible we want and we do.

77
00:05:25,080 --> 00:05:31,350
So I am pushing these three elements and then I am printing these three elements simple so let's then

78
00:05:31,350 --> 00:05:36,520
our program so basically we are getting added at this line and what does that.

79
00:05:36,520 --> 00:05:45,160
Let's see the edit is basically V was not declared in the scope so if you want to use vector what we

80
00:05:45,160 --> 00:05:48,880
have to do we have to include a file hash include vector

81
00:05:56,320 --> 00:06:01,990
so after including this file hash include vector it will not give us error so let's say in our program

82
00:06:04,650 --> 00:06:06,480
and this is my output.

83
00:06:06,480 --> 00:06:08,460
So that's how Victor is working

84
00:06:11,380 --> 00:06:11,920
now.

85
00:06:11,950 --> 00:06:16,710
Can I change the elements once I've inserted those elements obviously.

86
00:06:16,930 --> 00:06:21,430
So what I will use I will use square brackets to change the elements.

87
00:06:21,430 --> 00:06:27,660
So suppose I want to change the element presented index 1 So what I will do V of 1 is let's say a hundred.

88
00:06:27,670 --> 00:06:29,660
So initially it was 20.

89
00:06:29,710 --> 00:06:31,340
Now I change its value 200.

90
00:06:31,350 --> 00:06:32,020
So let's see

91
00:06:35,300 --> 00:06:44,390
so then a hundred and then thirty initially this hundred it was 20 so this squared Beckett's just like

92
00:06:44,480 --> 00:06:45,610
it used to work in error.

93
00:06:45,650 --> 00:06:51,330
It would also work for vectors so since vector it also has square brackets.

94
00:06:51,340 --> 00:06:54,020
So what is the need of push back function.

95
00:06:54,070 --> 00:06:55,390
So what I want to say here is.

96
00:06:55,450 --> 00:06:58,090
So initially I have three elements inside the vector.

97
00:06:58,090 --> 00:07:04,390
Now let's push the fourth element so can I push the elements using this grid backwards just like we

98
00:07:04,390 --> 00:07:05,930
used to do in eddies.

99
00:07:05,950 --> 00:07:08,590
Can we do this too.

100
00:07:08,620 --> 00:07:10,520
Are these two lines valid.

101
00:07:10,660 --> 00:07:17,950
So let us try to understand so if you will think logically these two lines should not work because if

102
00:07:17,950 --> 00:07:21,980
these two lines worked then what is the use of pushback function.

103
00:07:22,030 --> 00:07:24,130
So that means these two lines will not work.

104
00:07:25,310 --> 00:07:27,470
So why do we need pushback function.

105
00:07:27,470 --> 00:07:29,930
What is the importance of push back function.

106
00:07:30,140 --> 00:07:35,150
So push back function inside the push back function what will do so there are checks implemented it

107
00:07:35,150 --> 00:07:39,400
will check what is the current size of the vector if the vector is getting filled.

108
00:07:39,410 --> 00:07:41,010
I have to double the size.

109
00:07:41,120 --> 00:07:43,670
So all these things are implemented in push back function.

110
00:07:43,690 --> 00:07:52,250
That's why for inserting the element we will always use push back function so if you will use this then

111
00:07:52,250 --> 00:07:52,940
what will happen.

112
00:07:52,940 --> 00:07:55,820
So the size of the vector will not increase.

113
00:07:55,970 --> 00:08:02,960
So size increase class size of the vector will not increase.

114
00:08:02,990 --> 00:08:04,580
So what are the elements.

115
00:08:04,580 --> 00:08:05,140
Do I have.

116
00:08:05,140 --> 00:08:06,100
So I have 10.

117
00:08:06,860 --> 00:08:09,110
Then I have 20 and then I have 30.

118
00:08:09,320 --> 00:08:10,610
Let's see what is happening here.

119
00:08:10,640 --> 00:08:17,450
So suppose initially let's say the size of the vector is basically 2 Let's say initially it is.

120
00:08:17,480 --> 00:08:24,550
Let us assume it is not 2 actually but let us assume the size of the initial vectors basically 2.

121
00:08:24,560 --> 00:08:25,710
So that means this.

122
00:08:25,930 --> 00:08:28,090
This line will create a vector of size 2.

123
00:08:28,160 --> 00:08:29,020
So what is happening.

124
00:08:30,190 --> 00:08:30,990
This is my back.

125
00:08:32,650 --> 00:08:39,730
Push then I can push 10 then I am pushing 20 so I can push 20 then in order to push 30 what will happen.

126
00:08:39,730 --> 00:08:44,200
The size then actively become double the size the vector is basically food.

127
00:08:44,620 --> 00:08:51,070
So you can push the 30 element and you can push one more element you can push when what element the

128
00:08:51,070 --> 00:08:53,110
size of the event base food.

129
00:08:53,140 --> 00:08:54,210
Now what I'm doing here.

130
00:08:54,210 --> 00:09:00,240
Change the second element so this is hundred now print okay.

131
00:09:00,470 --> 00:09:06,830
Now what they are doing you are pushing the fourth element so fourth element will be 1 0 0 2 but you

132
00:09:06,830 --> 00:09:08,610
are pushing the fifth element.

133
00:09:08,720 --> 00:09:15,920
So this is the fifth element and add this memory you are pushing 1 2 3 4.

134
00:09:16,000 --> 00:09:24,570
So basically my vector only has this much amount of memory so this memory does not belong to me.

135
00:09:25,620 --> 00:09:27,660
So this memory does not belongs to us.

136
00:09:27,660 --> 00:09:34,200
So basically you are pushing an element you are pushing an element at such a memory location and that

137
00:09:34,200 --> 00:09:35,940
number location does not belong to us.

138
00:09:36,330 --> 00:09:40,330
Okay so this is basically wrong and this is also wrong.

139
00:09:40,370 --> 00:09:42,570
So let us experiment with something.

140
00:09:42,650 --> 00:09:50,130
So let us experiment something so after pushing at fourth and fifth indexes let us push more elements

141
00:09:50,200 --> 00:09:57,560
so we don't push back let's say twenty three and let's do push

142
00:10:02,960 --> 00:10:03,200
okay.

143
00:10:03,210 --> 00:10:05,340
So in order to spend everything so

144
00:10:25,200 --> 00:10:25,440
okay.

145
00:10:25,460 --> 00:10:32,320
So if I will run my program which would be output so ideally what should be our output.

146
00:10:32,320 --> 00:10:35,830
So initially I have pushed 10 then 20 then 30.

147
00:10:35,830 --> 00:10:43,590
Then I change its value 200 then I am pushing so 1 0 0 2 and then I am pushing 1 2 3 4.

148
00:10:43,970 --> 00:10:53,460
And then we don't push back 23 and we don't push back to the default so if I will execute our code this

149
00:10:53,460 --> 00:10:54,360
should be my output.

150
00:10:54,390 --> 00:11:02,870
Ideally this should be an output Okay so please remember ten hundred thirty one 0 0 2 1 2 3 4 and then

151
00:11:02,900 --> 00:11:03,690
this one.

152
00:11:03,740 --> 00:11:06,440
So let's see where that output is correct or not.

153
00:11:08,060 --> 00:11:09,160
Let's delete this one

154
00:11:14,150 --> 00:11:19,120
so an order does allow program.

155
00:11:19,180 --> 00:11:20,950
So this is the output.

156
00:11:20,950 --> 00:11:24,710
So let's see whether our output was wrong or right.

157
00:11:24,760 --> 00:11:26,110
So as discussed.

158
00:11:26,110 --> 00:11:27,900
So ideally what should be our output.

159
00:11:27,900 --> 00:11:33,360
So what I pushed I pushed pen then Bush 20 then pushed 30 then change its value 200.

160
00:11:33,550 --> 00:11:40,690
Then I pushed using these square brackets 1 0 0 2 and 1 2 3 4 and then I used push back function to

161
00:11:40,690 --> 00:11:46,460
insert 2 3 4 and 23 and 2 3 4.

162
00:11:46,720 --> 00:11:54,170
So I leave my output should be this 1 but obviously this is our idle output is not coming out.

163
00:11:54,190 --> 00:11:55,280
So what is happening.

164
00:11:55,390 --> 00:11:59,880
So when you are using push malfunction to insert these elements what pushback function will do.

165
00:11:59,880 --> 00:12:02,090
It will push the element at the last.

166
00:12:02,110 --> 00:12:02,890
So for vector.

167
00:12:02,920 --> 00:12:08,440
This is the last 30 is the last because we didn't use push back function to insert these two elements

168
00:12:09,730 --> 00:12:14,390
we do not use push back function to insert these two elements somewhat push back function.

169
00:12:14,680 --> 00:12:16,360
This is the last index.

170
00:12:16,360 --> 00:12:21,670
So what will happen more should be output 10 then hundred then 30.

171
00:12:21,670 --> 00:12:35,740
So basically 23 will come here and then 2 3 4 so 2 3 4 and then basically so these two are removed and

172
00:12:35,740 --> 00:12:36,970
then what is happening so.

173
00:12:36,980 --> 00:12:42,550
So these two are basically lost then I'm accessing this memory location and then I'm accessing this

174
00:12:42,550 --> 00:12:43,480
memory location.

175
00:12:43,570 --> 00:12:49,940
So these telemetry location are basically garbage values and analogous these two garbage values are

176
00:12:49,940 --> 00:12:51,160
basically 0 1 0.

177
00:12:51,620 --> 00:12:55,860
So these two garbage values are basically zero and zero.

178
00:12:55,970 --> 00:12:59,750
It could have been anything but in our case they both had zero.

179
00:12:59,930 --> 00:13:04,000
So that's why you should not you should never use brackets to insert.

180
00:13:04,010 --> 00:13:05,450
You should always use pushback.

181
00:13:05,450 --> 00:13:05,870
Function

182
00:13:08,670 --> 00:13:10,060
now one more thing.

183
00:13:10,730 --> 00:13:20,640
So basically so basically how this function is able to access the sixth element and similarly the fifth

184
00:13:20,640 --> 00:13:28,370
element this is able to accept the sixth element because what it will do so it will say so underlying

185
00:13:28,370 --> 00:13:29,650
this is Amanda Lang Eddy.

186
00:13:30,020 --> 00:13:32,110
So it will go towards start address.

187
00:13:32,120 --> 00:13:38,000
It will take six jumps ahead and it will print what now it is present at this garbage location.

188
00:13:38,000 --> 00:13:39,130
So zero is present.

189
00:13:39,140 --> 00:13:46,220
That's why as you're always getting printed simple now I have a benefit of using these grid backwards

190
00:13:46,240 --> 00:13:52,110
and the alternate is basically add function the alternate is basically use of ad function.

191
00:13:52,250 --> 00:13:56,690
So let's see how we can use ad function and what is the difference between the ad function and the square

192
00:13:56,690 --> 00:14:01,830
brackets so one thing is quite clear here.

193
00:14:02,000 --> 00:14:13,490
This is very wrong so never use square brackets to insert elements because the size of the area will

194
00:14:13,490 --> 00:14:17,840
not increase the size of the vector will not increase the size will not become double.

195
00:14:18,230 --> 00:14:24,020
So this is wrong.

196
00:14:24,120 --> 00:14:25,860
Now let us use add function

197
00:14:28,790 --> 00:14:32,600
so obviously let's remove this one.

198
00:14:32,630 --> 00:14:37,770
Let's come on out everything so I want to use add function.

199
00:14:37,770 --> 00:14:41,370
So currently I have three elements and then two elements here.

200
00:14:41,370 --> 00:14:43,470
So the size of the vector is basically 5

201
00:14:46,750 --> 00:14:52,270
so c out v don't at add function really big index.

202
00:14:52,320 --> 00:15:00,880
So let us print what this present at the next full and let us also check what is present at index X

203
00:15:03,780 --> 00:15:09,170
so basically index 4 is a valid index the size of the vector is currently 5.

204
00:15:09,260 --> 00:15:11,270
So the last index is basically 4.

205
00:15:11,300 --> 00:15:19,340
So this is actually a valid index but index X is not valid index 6 is not a valid index.

206
00:15:19,340 --> 00:15:22,010
So if we will run our program let's see what will be our output

207
00:15:25,110 --> 00:15:31,430
so see what is the output so at the next food duty for this peasant.

208
00:15:31,550 --> 00:15:37,790
But at index 6 which is not a valid index you can see out of range the size of the vector is basically

209
00:15:37,790 --> 00:15:40,890
5 and you are trying to access the sixth element.

210
00:15:40,940 --> 00:15:42,410
So basically it is giving us.

211
00:15:42,430 --> 00:15:45,290
Edit It is giving us added.

212
00:15:45,470 --> 00:15:49,930
So what we can say so this ad function.

213
00:15:50,350 --> 00:15:56,850
It basically checks whether the index is valid or invalid.

214
00:15:56,930 --> 00:16:03,670
So basically we can see that using the add function is much much safer than using this square backward.

215
00:16:03,920 --> 00:16:09,060
So add is much much safer because it will check the index if you will.

216
00:16:09,080 --> 00:16:11,290
So if you will right we got at 6.

217
00:16:11,300 --> 00:16:16,460
It will give us error that the size of the vector is basically 5 and you and you cannot access index

218
00:16:16,460 --> 00:16:20,540
X but if we will use the square brackets 6 then what will happen.

219
00:16:20,750 --> 00:16:22,160
It will go just like an array.

220
00:16:22,160 --> 00:16:23,840
It will go to the starting position.

221
00:16:23,990 --> 00:16:29,090
It will take six jumps ahead and it will print out everything whatever it is present.

222
00:16:29,090 --> 00:16:33,190
So the output will be garbage now which one is better.

223
00:16:33,460 --> 00:16:36,020
So obviously this memory does not belong to us.

224
00:16:36,040 --> 00:16:39,350
So this is basically very bad.

225
00:16:39,370 --> 00:16:40,900
Obviously this is much better.

226
00:16:40,900 --> 00:16:43,600
So this is much safer using the add function is safer.

227
00:16:44,170 --> 00:16:44,470
Okay.

228
00:16:44,480 --> 00:16:46,080
So.

229
00:16:46,320 --> 00:16:52,830
So now let us use for loop to I told our director so how we can use for loop so let us comment out everything

230
00:16:56,190 --> 00:17:01,810
so let's use for loop so just like we used to isolate over the array.

231
00:17:01,940 --> 00:17:08,540
We can also add later with the vector so i equals zero i.e. less than we thought size now Vidor size.

232
00:17:08,560 --> 00:17:12,420
This is an build function or don't give me how many elements are present inside the vector.

233
00:17:12,430 --> 00:17:17,280
So currently 5 elements are present so the value of your size is 5.

234
00:17:17,470 --> 00:17:21,280
And here you can use vilify.

235
00:17:21,280 --> 00:17:25,970
And here you can use the square brackets and you can use at.

236
00:17:25,990 --> 00:17:27,260
So at this.

237
00:17:27,660 --> 00:17:30,700
So inside the for loop both you can use both.

238
00:17:30,700 --> 00:17:36,820
You can use Square Beckett and you can also use at the boathouse same way because index is always valued

239
00:17:37,390 --> 00:17:43,680
because of the for loop Woodward size will be 5 here inside the for loop it is safe to use board square

240
00:17:43,690 --> 00:17:50,520
brackets as well as the add function Mutassim so if you will run the program what will be our output.

241
00:17:50,660 --> 00:17:59,750
It will print the content of the vector so this is the content then handed today 23 and 24.

242
00:17:59,790 --> 00:18:02,380
So now we know how do I get over direct bed.

243
00:18:02,430 --> 00:18:07,200
So just like the pushback function I also have Bob back.

244
00:18:07,280 --> 00:18:11,090
So what Bob that function will do so v dot Bob back

245
00:18:15,600 --> 00:18:17,170
So bob back function what it will lose.

246
00:18:17,180 --> 00:18:19,260
So it will pop out the last element.

247
00:18:20,610 --> 00:18:25,890
So what is the use of pushback Pushback will insert the element at last.

248
00:18:26,060 --> 00:18:29,060
And Bob Beck will remove the last element.

249
00:18:29,090 --> 00:18:31,490
So basically this was the last element to form.

250
00:18:31,490 --> 00:18:36,750
So this element will be removed and the seismic activity become forward so four elements will be printed.

251
00:18:36,770 --> 00:18:37,220
Let's see

252
00:18:43,460 --> 00:18:48,140
so four elements are getting printed the size the vectors containing only four elements

253
00:18:53,070 --> 00:18:54,740
normally just kind out everything.

254
00:18:54,800 --> 00:18:56,870
And let's do some experiments

255
00:19:02,540 --> 00:19:10,350
so let us use a for loop to insert the elements inside the vector so let's say I want to push a hundred

256
00:19:10,350 --> 00:19:16,610
elements so when it does push hundred elements so we don't push back

257
00:19:19,770 --> 00:19:31,260
a plus one so I am pushing hundred elements and let us also print out our vector so I equals zero.

258
00:19:31,260 --> 00:19:35,840
I list and we out size and I plus plus

259
00:19:39,530 --> 00:19:40,520
C outreach if I

260
00:19:43,800 --> 00:19:49,070
so I am pushing hundred elements and then I am printing those hundred elements simple.

261
00:19:49,090 --> 00:19:49,700
Let's see

262
00:19:54,230 --> 00:19:58,760
so these are the elements inserted starting from when they landed.

263
00:19:58,760 --> 00:20:01,790
So yes civil code is working fine.

264
00:20:01,900 --> 00:20:03,700
Now let us see.

265
00:20:04,190 --> 00:20:06,730
Now let us also print the size.

266
00:20:06,820 --> 00:20:08,510
So when I am pushing the elements.

267
00:20:08,530 --> 00:20:10,690
Let us also print the size of the vector.

268
00:20:11,200 --> 00:20:14,320
So see out v dot size

269
00:20:17,710 --> 00:20:17,940
now.

270
00:20:17,950 --> 00:20:23,190
What should be our output what we what size will contain.

271
00:20:23,190 --> 00:20:27,150
So this size function foster it will contain one element.

272
00:20:27,150 --> 00:20:29,580
Then it will contain two then three then four.

273
00:20:29,580 --> 00:20:33,690
So basically this Vidor size it will increase linearly.

274
00:20:33,690 --> 00:20:37,780
And finally the size of the vector will become a hundred simple.

275
00:20:37,800 --> 00:20:42,990
There should be an output 1 200 the size the Vidor size.

276
00:20:43,030 --> 00:20:46,140
So the size of a vector will increase one by one.

277
00:20:46,150 --> 00:20:58,680
Simple so let's remove this thing and now we are liberating the size so let us also right size it what

278
00:20:58,680 --> 00:20:59,790
is the size of the vector

279
00:21:03,040 --> 00:21:07,530
and let's give and line also so let's see

280
00:21:11,160 --> 00:21:16,930
so you can see when you push it when you enter size will become one when you push the second element

281
00:21:16,930 --> 00:21:18,130
the size becomes too.

282
00:21:18,190 --> 00:21:20,440
When you push the third element the size becomes three.

283
00:21:20,470 --> 00:21:21,260
And so on.

284
00:21:21,430 --> 00:21:26,370
And finally when you will push the hundredth element the size of the vector will you become a hundred

285
00:21:26,710 --> 00:21:28,800
simple.

286
00:21:28,810 --> 00:21:34,550
Now we also have a function capacity so I have a function capacity.

287
00:21:34,550 --> 00:21:37,020
So what this capacity function will do.

288
00:21:37,160 --> 00:21:43,400
So it will give me what is the capacity what is the current capacity of my vector that will give me

289
00:21:43,430 --> 00:21:50,510
what is the current capacity of my vector and the difference between capacity and sizes size will give

290
00:21:50,510 --> 00:21:52,190
me how many elements at present.

291
00:21:52,190 --> 00:21:55,540
So for example let's say three elements are present.

292
00:21:55,550 --> 00:22:00,860
So size will give me that three elements that present me this capacity will give me how many elements

293
00:22:01,010 --> 00:22:04,670
you can insert inside the vector for example for example six.

294
00:22:04,670 --> 00:22:07,390
So the capacity will be six.

295
00:22:07,430 --> 00:22:12,980
Now let us print but we will print capacity and size and I'll deliver it should happen.

296
00:22:12,980 --> 00:22:18,460
So that capacity will become double capacity will become double as soon as the vector is full.

297
00:22:18,470 --> 00:22:19,580
So let's check it out

298
00:22:23,920 --> 00:22:25,750
so let's print the capacity

299
00:22:32,470 --> 00:22:35,730
b don't capacity.

300
00:22:35,830 --> 00:22:42,790
So this is also an build function function of basically vector and let's remove sides from here

301
00:22:50,850 --> 00:22:53,790
okay so let's Renamo code and let's see what will happen

302
00:23:01,000 --> 00:23:03,380
so let's try to understand what is happening here.

303
00:23:03,400 --> 00:23:08,350
So initially the capacities 0 and the size is also 0.

304
00:23:08,620 --> 00:23:10,750
Strange array of size 0.

305
00:23:10,750 --> 00:23:17,700
So basically this means that at starting and it didn't really exist and is basically null it doesn't

306
00:23:17,740 --> 00:23:24,700
exist when you push the first element the capacity becomes 1 and the size becomes 2 when you will push.

307
00:23:24,700 --> 00:23:31,000
So this is the first element the capacity is 1 in the size is when so many will push the second element

308
00:23:31,680 --> 00:23:33,280
that capacity will become place.

309
00:23:33,280 --> 00:23:39,850
So this is the capacity capacity becomes two and size is also 2 when you will push the third element.

310
00:23:39,860 --> 00:23:44,840
The capacity will become for the size will become double the capacity will become double the size the

311
00:23:44,840 --> 00:23:46,880
vector is basically for now.

312
00:23:46,880 --> 00:23:52,100
So you can push the fourth element and the capacity is still full but when you're pushing the fifth

313
00:23:52,100 --> 00:23:54,860
element the capacity becomes double.

314
00:23:54,860 --> 00:24:02,780
So the capacity it's basically the vector capacities it so you can safely push element six.

315
00:24:02,780 --> 00:24:07,730
You can push the element seven you can push element date but when you are trying to push the ninth element

316
00:24:07,970 --> 00:24:17,420
the capacity doubles so it will become sixteen so you can push that element girl 13 14 and so on.

317
00:24:17,420 --> 00:24:24,140
So finally when you will try to push the 17th element capacity will become 32 and so on.

318
00:24:24,140 --> 00:24:26,930
So it will keep going on.

319
00:24:26,960 --> 00:24:34,150
So finally let's see so finally the capacity is undaunted.

320
00:24:34,220 --> 00:24:38,180
And this is enough to hold a hundred elements.

321
00:24:38,180 --> 00:24:44,820
So capacity 128 is enough to hold these main number of elements okay.

322
00:24:44,840 --> 00:24:50,660
So we have seen how to create best and dynamically we know how to push elements.

323
00:24:50,660 --> 00:24:56,290
We know the capacity function we know the size function we know the public back function.

324
00:24:56,290 --> 00:25:02,440
So this when we dart ball back we know how to pop element we know how to push element we know how to

325
00:25:02,440 --> 00:25:06,960
change the elements we know how do I create all the director.

326
00:25:07,730 --> 00:25:12,500
So pretty much we know all the major functions of Director Okay.

327
00:25:12,520 --> 00:25:20,970
So when lasting how to create a vector of a given size for example I want to create a vector let's say

328
00:25:20,970 --> 00:25:25,500
of size 10 so you can give size here to giving size is optional.

329
00:25:25,500 --> 00:25:30,630
If you want to give the size you can if you don't want to give then don't give okay.

330
00:25:30,640 --> 00:25:37,210
So what if you want to initialize this vector so comma let's say I want to initialize this vector with

331
00:25:37,210 --> 00:25:43,860
the minus two so this victory has been initialized all the 10 values are basically minus two.

332
00:25:43,880 --> 00:25:44,740
You can also see.

333
00:25:45,620 --> 00:25:57,530
So let us print this vector OK let's change the name B to so equals zero list and we do a plus plus

334
00:25:59,530 --> 00:26:00,520
and see out

335
00:26:03,520 --> 00:26:03,970
symbol

336
00:26:08,120 --> 00:26:08,340
okay.

337
00:26:08,350 --> 00:26:10,000
So we do large sites

338
00:26:21,400 --> 00:26:27,100
so we'll see the vector has been interfaced or the 10 elements are minus two.

339
00:26:27,120 --> 00:26:28,910
So that's how you initialize of the

340
00:26:33,200 --> 00:26:35,210
so it is not necessary to initialize the vector.

341
00:26:35,660 --> 00:26:43,050
So if you write like this vector of indigenous v V3 and you can only give size.

342
00:26:43,130 --> 00:26:44,480
So this is also correct.

343
00:26:45,140 --> 00:26:48,630
Okay so can we start the vector.

344
00:26:48,740 --> 00:26:50,950
So yes we can start direct it.

345
00:26:51,110 --> 00:26:52,760
I haven't ruled functions out.

346
00:26:52,910 --> 00:26:53,710
So what do we do.

347
00:26:54,970 --> 00:27:00,280
I will write like this for example I want to sort vector we to suicide we do not begin

348
00:27:03,310 --> 00:27:08,970
we do dart and so just like Eddie we have to give the starting in the end items.

349
00:27:09,190 --> 00:27:16,590
So sort of you got begin and we do not end and my vector will become sorted my vector will be sorted.

350
00:27:16,680 --> 00:27:23,790
Okay so we know how to initialize we know how to give how to create a vector of a given size we know

351
00:27:23,790 --> 00:27:29,490
how to sort of vector so pretty much we know all the functions all the major functions of the vector

352
00:27:30,770 --> 00:27:31,000
okay.

353
00:27:31,010 --> 00:27:33,480
So I think this is enough.

354
00:27:33,480 --> 00:27:35,420
I will show you in the next one by.
