1
00:00:00,150 --> 00:00:06,780
This is basically just saying that we tried to access something out of bounds in this case, the vector

2
00:00:06,960 --> 00:00:08,670
basically looked like this.

3
00:00:12,510 --> 00:00:18,660
It was just empty and we were just like, Get me the first thing out of this empty vector, as if there

4
00:00:18,660 --> 00:00:20,490
was some type of number in there like that.

5
00:00:21,120 --> 00:00:21,830
But there wasn't.

6
00:00:21,840 --> 00:00:23,130
And so we got a segfault.

7
00:00:25,130 --> 00:00:30,320
So we declared our vector, but we didn't really declare like a size or anything, right?

8
00:00:30,590 --> 00:00:31,990
We didn't make it like an array.

9
00:00:32,000 --> 00:00:33,710
We just gave it like a variable name.

10
00:00:34,160 --> 00:00:35,900
How do we put stuff in our vector?

11
00:00:36,890 --> 00:00:45,260
Well, we actually can use one of these nifty functions that I was talking about and the way that we

12
00:00:45,260 --> 00:00:54,350
use a function with the vector, like a special function that's meant for vectors is to use a dot with

13
00:00:54,380 --> 00:00:55,700
the vectors name.

14
00:00:56,330 --> 00:01:02,570
So I can say in my vest and then I use a dot to access the function.

15
00:01:03,590 --> 00:01:09,530
And the first function I'm going to mention is something called push underscore it back.

16
00:01:11,180 --> 00:01:17,470
So, you know, this is a function call because it has these parentheses right here in parentheses.

17
00:01:19,100 --> 00:01:23,420
Push back, just add something to the end of the vector.

18
00:01:24,170 --> 00:01:29,140
So whatever, I want to add an end of the vector I put as an argument to the function here.

19
00:01:29,150 --> 00:01:34,340
So if I put three, it's going to take our vector from being something like this

20
00:01:37,520 --> 00:01:42,200
to being something like this.

21
00:01:43,860 --> 00:01:48,840
So it's going to add that three to it, if I was to call a push back again and put three in it again,

22
00:01:49,470 --> 00:01:55,320
then it would put another one, yet another three at the end of the victory, and it would look like

23
00:01:55,320 --> 00:01:55,590
that.

24
00:01:57,270 --> 00:02:05,100
So just something to remember when you want to call one of these functions on the vector, you put this

25
00:02:05,100 --> 00:02:09,150
dot here in this specific function called push underscore back.

26
00:02:09,780 --> 00:02:16,650
Its purpose is to put whatever we took or whatever we put in here is going to put it at the end of our

27
00:02:16,650 --> 00:02:17,160
vector.

28
00:02:18,260 --> 00:02:23,820
And now that we have something in our vector, it basically went from being empty like this right to

29
00:02:23,820 --> 00:02:26,250
now having this three in it.

30
00:02:26,580 --> 00:02:30,320
That means that we do have something at positions here, right?

31
00:02:30,330 --> 00:02:32,610
So this should not be a problem anymore.

32
00:02:32,610 --> 00:02:37,110
We should be able to access this first and only item in our vector.

33
00:02:39,560 --> 00:02:46,640
So let's confirm that let's make sure that we this victory that we declare here, let's make sure that

34
00:02:46,640 --> 00:02:49,070
it actually did add this three to it.

35
00:02:49,250 --> 00:02:54,530
And then here, if that was true, then what this should print out is just the number three.

36
00:02:56,030 --> 00:02:57,920
So I'm going to re compile.

37
00:03:00,760 --> 00:03:02,650
And I'm going to run it on out again.

38
00:03:03,190 --> 00:03:05,140
And there we see that we get our three.

39
00:03:06,140 --> 00:03:09,470
So it was added to the record, just to be even more sure.

40
00:03:09,800 --> 00:03:13,370
I'm going to go ahead and use another function now.

41
00:03:13,560 --> 00:03:14,060
So.

42
00:03:16,000 --> 00:03:24,850
Well, I'm going to do is use a function called size, so I'm going do my vegan diet right to access

43
00:03:24,850 --> 00:03:30,730
the function and then I'm going to use the size function and it just doesn't take any parameters in

44
00:03:30,730 --> 00:03:31,060
here.

45
00:03:31,480 --> 00:03:37,120
And what it's going to do is actually give me the current size of the vector.

46
00:03:37,140 --> 00:03:43,750
So if our vector has one thing in it at position zero, just one thing the size will be one.

47
00:03:44,820 --> 00:03:50,340
In fact, Victor has no things in it, if it's empty, it'll be so zero director has three things in

48
00:03:50,340 --> 00:03:51,450
it, it would be so three.

49
00:03:51,660 --> 00:03:52,620
So on and so forth.

50
00:03:53,880 --> 00:03:56,370
So I want to print that out.

51
00:03:57,630 --> 00:04:05,460
I'm going to say see out my right the size of the first line that prints out should be the size of the

52
00:04:05,460 --> 00:04:06,030
vector.

53
00:04:07,260 --> 00:04:08,310
And you know what I'll do.

54
00:04:08,310 --> 00:04:11,850
I'll actually say I was criticized here at

55
00:04:14,820 --> 00:04:15,750
a little space.

56
00:04:16,890 --> 00:04:24,600
And then let's also copy paste this line, and we will put it.

57
00:04:29,320 --> 00:04:39,190
Put it right here, so I'll also say that because zero.

58
00:04:43,330 --> 00:04:44,010
Right here.

59
00:04:44,320 --> 00:04:49,240
So that way, we can see what printout we can explain what we're printing out.

60
00:04:50,350 --> 00:04:54,130
So let's see what the size is once I declare it right after I declare my victory.

61
00:04:54,590 --> 00:04:58,660
We'll get the size, then we'll push back three.

62
00:04:58,840 --> 00:05:06,520
Then we'll see that it's stored in there and then we'll see what the size is after I went to recompile

63
00:05:07,180 --> 00:05:08,110
around eight on out.

64
00:05:09,630 --> 00:05:14,850
OK, so here we go, look at this, so it says size is zero right after we just declared it right,

65
00:05:15,630 --> 00:05:22,140
then what we did was we pushed back a three to the vector in between these two things.

66
00:05:23,120 --> 00:05:30,080
And now and then we printed out what was at the first position in the vector, which is only at three

67
00:05:30,080 --> 00:05:32,390
in it and the thing at position zero three.

68
00:05:33,520 --> 00:05:38,440
Then we printed out the size now, and it said the size is one because it has one item in it.

69
00:05:38,550 --> 00:05:38,800
All right,

70
00:05:41,800 --> 00:05:42,190
cool.

71
00:05:42,190 --> 00:05:48,280
So we can see that there's some pretty cool functionality with this that kind of sets it apart from

72
00:05:48,520 --> 00:05:49,690
just an array, right?

73
00:05:50,200 --> 00:05:54,830
We just were able to declare it right here and then we can just start adding stuff to it and getting

74
00:05:54,830 --> 00:05:57,130
the information about how many things are in it.

75
00:05:57,910 --> 00:06:00,100
Pretty, pretty neat, honestly.

76
00:06:00,110 --> 00:06:03,180
So let's go ahead.

77
00:06:03,200 --> 00:06:10,330
I'm going to add another item to it, so I'll say my right that push back, and I'm just going to add

78
00:06:10,330 --> 00:06:11,320
this for to it.

79
00:06:12,610 --> 00:06:16,060
And then we'll put another size right here.

80
00:06:20,420 --> 00:06:27,830
And then let's use even yet another function, so I'm going to say my back and this is just like push

81
00:06:27,830 --> 00:06:29,480
back, except it's kind of the opposite.

82
00:06:29,480 --> 00:06:37,550
Instead of adding something, it just reduces the size of the vector by one, and that is called pop

83
00:06:37,550 --> 00:06:37,880
effect.

84
00:06:39,260 --> 00:06:43,010
So that's basically reducing the size of the vector by one.

85
00:06:43,220 --> 00:06:51,140
So we'll put a pop back in here and I will put another size right here.

86
00:06:53,360 --> 00:06:59,150
So we'll call, let's just say, size after pop that.

87
00:07:02,690 --> 00:07:05,030
And so we have another pushback here.

88
00:07:06,550 --> 00:07:10,390
Maybe you will actually print this out to.

89
00:07:16,770 --> 00:07:18,150
Okay, so

90
00:07:20,760 --> 00:07:22,990
we'll do my next one.

91
00:07:24,260 --> 00:07:32,290
All right, because once we have this next item in it, we push back at three and that's it in zero.

92
00:07:32,430 --> 00:07:34,980
And then we get a size and then push back a four.

93
00:07:35,250 --> 00:07:42,840
So the vector is basically looking something like this three as it is at position zero four, is it

94
00:07:42,840 --> 00:07:43,770
position one?

95
00:07:44,640 --> 00:07:48,510
So that's why we all do this position one.

96
00:07:48,510 --> 00:07:49,110
Print that out.

97
00:07:53,530 --> 00:08:00,390
And then we'll get this size after the putback, so we'll pop back and then we'll get that size, so

98
00:08:00,550 --> 00:08:08,830
it should be something like size zero prints out three sizes, one pushes back.

99
00:08:09,280 --> 00:08:12,700
Here it prints out four because that's the thing we push back.

100
00:08:12,970 --> 00:08:16,210
And then here it should say that the size is two, because there's two things in it.

101
00:08:16,660 --> 00:08:20,140
We pop back in and the size should not be two anymore should go back to one.

102
00:08:21,370 --> 00:08:24,640
So let's compile this and let's run it.

103
00:08:26,110 --> 00:08:28,570
So there we see size starts out as zero.

104
00:08:30,590 --> 00:08:36,440
Then what we did is we added three, and it shows the three, and then it says size is one.

105
00:08:38,450 --> 00:08:43,010
Then we added a four to it and we print out my next one in a four.

106
00:08:43,430 --> 00:08:44,840
Then we say, What's the size now?

107
00:08:44,840 --> 00:08:45,890
The size is two.

108
00:08:46,190 --> 00:08:51,770
Then we do a pop back and then the size after the pop back, it says now is back to one

109
00:08:54,890 --> 00:08:55,230
cool.

110
00:08:55,280 --> 00:09:00,050
So what if I don't really know how many items are in my vector, but I just want to know what's at the

111
00:09:00,050 --> 00:09:01,940
end of the vector?

112
00:09:02,360 --> 00:09:07,880
So rather than doing like my Vector zero and my vector one, I can use yet another function.

113
00:09:08,630 --> 00:09:15,950
And this is going to be my vector back, and that'll just give me whatever item is at the very end of

114
00:09:15,950 --> 00:09:16,490
the vector.

115
00:09:18,110 --> 00:09:20,810
So now this should print out the same thing.

116
00:09:26,750 --> 00:09:32,290
The same thing as we had before, but instead, we're using this function, we're not acting like we

117
00:09:32,290 --> 00:09:33,610
know what's in the vector.

118
00:09:33,820 --> 00:09:36,850
We're just pretending anything could have gotten added.

119
00:09:36,850 --> 00:09:40,690
There could be whatever elements, but we want to know what's at the back each time.

120
00:09:40,760 --> 00:09:41,080
Right.

121
00:09:41,530 --> 00:09:43,930
We want to know what the very last thing in the vector is.

122
00:09:45,700 --> 00:09:49,030
So we have this right here is what came out previously.

123
00:09:49,060 --> 00:09:53,590
Let's go ahead and re compile and then let's run it again.

124
00:09:56,150 --> 00:10:01,220
And so we notice, you know, here, I didn't put the my big zero in my wrecked one, but we got the

125
00:10:01,220 --> 00:10:03,500
same results as before, right?

126
00:10:03,830 --> 00:10:04,970
Size is zero.

127
00:10:05,300 --> 00:10:10,100
Then we print out the last thing in it, which is there's only one thing, which is three that says,

128
00:10:10,100 --> 00:10:11,120
Hey, the size is one.

129
00:10:11,510 --> 00:10:14,500
Then we added the four and we printed out the last thing in it.

130
00:10:14,510 --> 00:10:16,640
And that's four because there's two items now.

131
00:10:17,090 --> 00:10:18,320
And then we said, What's the size?

132
00:10:18,320 --> 00:10:19,280
The size is, too.

133
00:10:19,730 --> 00:10:23,240
Then we did a pop back and then it says the size after the pop back is one.

134
00:10:24,860 --> 00:10:25,790
So pretty cool.

135
00:10:25,800 --> 00:10:28,640
We noticed there's quite a bit of functionality here with the vector.

136
00:10:30,710 --> 00:10:36,710
So whenever you want to call some of these functions on the vector, just remember that you're going

137
00:10:36,710 --> 00:10:39,860
to use that dot and then the name of the function.

138
00:10:40,790 --> 00:10:43,010
So how do you figure out all of the functions?

139
00:10:43,010 --> 00:10:47,660
Where do you and where can you find a list of all of these functions you can use with your vector?

140
00:10:49,240 --> 00:10:55,060
That's something like right here that you can refer to, for example, C++ dot com.

141
00:10:55,850 --> 00:10:59,430
You want to see if I can enlarge this a bit.

142
00:11:01,070 --> 00:11:02,840
OK, so we can see a little better.

143
00:11:03,650 --> 00:11:09,170
So here we have pushed back and putt putt putt putt back right here.

144
00:11:09,200 --> 00:11:16,550
You notice there some example code where they're pushing back 100, pushing back 200, 300 and all that.

145
00:11:17,480 --> 00:11:21,080
Here's actually a nice list of all of these functions.

146
00:11:21,150 --> 00:11:24,530
These are called member functions because they are members of the class.

147
00:11:24,530 --> 00:11:28,250
But remember, don't focus too hard on that right now.

148
00:11:28,460 --> 00:11:31,100
We're going to get into talking about classes and all that.

149
00:11:31,610 --> 00:11:35,870
Just know that you can put a dot and then each one of these names here.

150
00:11:37,510 --> 00:11:41,290
To do kind of different things like, let's look at this right here clear.

151
00:11:43,120 --> 00:11:50,110
This tells us what the clear function does, removes all elements from the vector which are destroyed,

152
00:11:50,560 --> 00:11:53,440
leaving the container with the size of zero.

153
00:11:54,160 --> 00:11:54,550
Huh.

154
00:11:54,580 --> 00:11:55,360
Interesting.

155
00:11:55,370 --> 00:12:04,810
So what if we go back to our code here and we have size after pop back, right?

156
00:12:04,810 --> 00:12:08,620
Because we did this pop back, our size was too right here.

157
00:12:08,650 --> 00:12:14,110
What if instead of pop back, we just did clear.

158
00:12:16,300 --> 00:12:18,760
So our size after pop back was one, right?

159
00:12:18,770 --> 00:12:24,850
So now let's see what our size is actually clear should be zero, right?

160
00:12:25,300 --> 00:12:28,120
So let's run it in there.

161
00:12:28,120 --> 00:12:29,830
You notice the size was two.

162
00:12:30,280 --> 00:12:36,400
We did our clear function and it says size after a career is zero, so it removed everything from the

163
00:12:36,400 --> 00:12:36,910
vector.

164
00:12:40,280 --> 00:12:43,460
Cool, so, yeah, there's a lot more functions you can use here.

165
00:12:43,760 --> 00:12:48,950
And this is just kind of supposed to make your life a little bit easier.

166
00:12:49,400 --> 00:12:53,180
You know, arrays are great and this great to great practice to use them.

167
00:12:53,180 --> 00:13:01,130
And sometimes they have benefits over a vector and over other data structures that will go over.

168
00:13:02,330 --> 00:13:08,210
I won't go into that too much right now about, you know, how much space stuff takes up and how fast

169
00:13:08,210 --> 00:13:10,040
things are and efficient things are.

170
00:13:10,070 --> 00:13:13,280
That's something that we're going to go deep into later in the course.

171
00:13:14,270 --> 00:13:20,270
But right now, just know that this is kind of a fancy array that you can use, if you would like,

172
00:13:21,440 --> 00:13:24,540
you just kind of declare it like this here.

173
00:13:24,560 --> 00:13:26,180
Of course they're not using.

174
00:13:27,230 --> 00:13:33,650
Well, namespace, they're putting this study, Colin Colin, with the scope resolution here.

175
00:13:34,670 --> 00:13:37,160
To be able to use the vector.

176
00:13:38,350 --> 00:13:43,630
But just like we did, they made a vector of integers, they call it my vector rather than my vector.

177
00:13:44,620 --> 00:13:47,830
And they did make sure to push back here a few times.

178
00:13:48,160 --> 00:13:52,690
Here we have some looping stuff that you can kind of ignore.

179
00:13:53,530 --> 00:13:58,360
But then they do clear and they do more push backs here.

180
00:14:00,650 --> 00:14:06,470
So it's just kind of demonstrates, you know, they have a nice little code snippets here that demonstrate

181
00:14:06,470 --> 00:14:08,060
how to use these functions.

182
00:14:10,610 --> 00:14:13,940
And here you notice there's some other things he is like back.

183
00:14:14,360 --> 00:14:16,580
We also have begin.

184
00:14:19,900 --> 00:14:22,330
So actually, let's look at front.

185
00:14:23,570 --> 00:14:28,310
So a reference to the front of the vector, so we can't even try that out.

186
00:14:29,690 --> 00:14:31,880
What about we have this?

187
00:14:32,570 --> 00:14:34,480
My vector back, right?

188
00:14:35,930 --> 00:14:37,850
So let's just say

189
00:14:40,990 --> 00:14:42,770
back of the vector.

190
00:14:49,260 --> 00:14:50,130
And then.

191
00:14:55,270 --> 00:14:56,800
Put the same thing here.

192
00:14:57,340 --> 00:14:57,770
Oops.

193
00:15:04,010 --> 00:15:08,750
So we'll say the back of the vector is right here and then.

194
00:15:11,680 --> 00:15:13,990
Let's also do a.

195
00:15:17,930 --> 00:15:23,260
Front of the victory, so as to see out front of the.

196
00:15:26,770 --> 00:15:29,330
So this will be like my ex got front.

197
00:15:31,300 --> 00:15:34,180
So this is where we had three in it, right?

198
00:15:34,900 --> 00:15:37,410
And then we also push back a four.

199
00:15:37,420 --> 00:15:41,260
It'll show the back of the picture, which is four, because that's at the end and then the front should

200
00:15:41,260 --> 00:15:42,370
be a three, right?

201
00:15:43,780 --> 00:15:47,290
So let's go ahead and compile this and run it.

202
00:15:49,470 --> 00:15:49,890
Cool.

203
00:15:49,920 --> 00:15:56,780
So there you see that my dog front was able to get us what was in the front of the victor.

204
00:15:57,700 --> 00:16:03,250
So basically, it was like you, we pushed back the three, right, and that's what's in the back,

205
00:16:03,250 --> 00:16:04,600
it said, besides this one.

206
00:16:05,350 --> 00:16:09,130
Then we pushed back a four before this line and we say, what's at the back?

207
00:16:09,160 --> 00:16:09,700
It's a four.

208
00:16:09,700 --> 00:16:12,940
We just added that what's at the front of the vector?

209
00:16:13,210 --> 00:16:14,860
That's three that three is still in.

210
00:16:14,860 --> 00:16:17,710
There is the first thing right in the size is two.

211
00:16:18,070 --> 00:16:21,640
And then we cleared it in the Air Force ActionScript zero for size.

212
00:16:23,860 --> 00:16:24,340
All right.

213
00:16:24,640 --> 00:16:27,080
So that's pretty much all.

214
00:16:27,080 --> 00:16:29,670
I'm going to go over for the vectors right now.

215
00:16:30,190 --> 00:16:38,890
Be really great to look over this reference right here and read up on them this this code might have

216
00:16:38,890 --> 00:16:46,360
some things that you are maybe not as comfortable with or might not know about yet, and that's totally

217
00:16:46,360 --> 00:16:46,960
fine.

218
00:16:47,440 --> 00:16:49,150
Just kind of take it for what it is.

219
00:16:49,150 --> 00:16:57,790
And, you know, so look at the code that it makes sense to you, like some of some stuff that we've

220
00:16:57,790 --> 00:17:01,570
only covered yet, you know, you can kind of just like, look at how that's used.

221
00:17:01,570 --> 00:17:04,600
If you see something else that doesn't make sense, you don't need to try and use that.
