1
00:00:00,540 --> 00:00:09,060
Today, we are going to go over the actual code implementation of a singly linked list.

2
00:00:10,360 --> 00:00:16,810
So that was the first one that we talked about in the slideshow, which was more theoretical explanation

3
00:00:16,810 --> 00:00:17,770
of link lists.

4
00:00:18,310 --> 00:00:20,890
Now we are going to write the code for it.

5
00:00:21,550 --> 00:00:29,470
So I went ahead and created a new project in Sea Lion, just called it singly linked list, and it gave

6
00:00:29,470 --> 00:00:40,210
me a main file here and main function, which we will be using as our client file to instantiate the

7
00:00:40,210 --> 00:00:43,480
link list and prove that it works.

8
00:00:43,750 --> 00:00:45,490
So I'm going to go ahead and leave it, but delete that.

9
00:00:45,490 --> 00:00:46,630
Hello world, of course.

10
00:00:47,710 --> 00:00:51,970
And I'm just going to leave main CBP alone for now.

11
00:00:52,900 --> 00:00:58,410
And so today is going to be a very basic.

12
00:00:58,420 --> 00:01:04,330
We're just going to make like a super barebones version of a linked list, so it's not going to have

13
00:01:04,840 --> 00:01:07,180
everything that it probably should have.

14
00:01:08,290 --> 00:01:11,530
We will go into that and some of the next videos.

15
00:01:11,530 --> 00:01:17,920
But right now, it's just kind of making the link list data structured just enough to show that it works

16
00:01:17,920 --> 00:01:21,400
and that we know what those pointers are doing and everything.

17
00:01:21,730 --> 00:01:25,060
And it'll just be kind of a proof of concept.

18
00:01:25,060 --> 00:01:30,910
But so we're not going to add like an assignment operator or any overloaded operators or a copy constructor

19
00:01:30,910 --> 00:01:31,420
or anything.

20
00:01:31,420 --> 00:01:37,600
We're just going to kind of do the least work that we can to get a link list up and going.

21
00:01:38,440 --> 00:01:44,320
So I'm going to go ahead and create my first class here.

22
00:01:44,330 --> 00:01:45,760
I'm going to make a header file.

23
00:01:46,330 --> 00:01:50,170
This is going to be for the nodes of the link list.

24
00:01:50,440 --> 00:02:00,130
So for make this new header file and I'm going to call it El Node, so that's going to be L.A. H.

25
00:02:03,190 --> 00:02:03,580
All right.

26
00:02:03,670 --> 00:02:06,880
And so let's define our L.A. class

27
00:02:09,670 --> 00:02:11,830
and put a public section here.

28
00:02:12,020 --> 00:02:22,090
We're going to make our constructor and then the next thing I'm going to do is make a function that

29
00:02:22,090 --> 00:02:25,780
can return the pointer to the next node.

30
00:02:28,090 --> 00:02:32,890
And so that is going to be returning an L node pointer.

31
00:02:32,890 --> 00:02:34,450
And I'm going to call it next.

32
00:02:36,070 --> 00:02:45,180
And then I'm going to make a function that can set the next node, so that is going to be a void function,

33
00:02:45,190 --> 00:02:50,740
and I'm going to pass it a node pointer, then I'm going to call next as well.

34
00:02:53,440 --> 00:02:59,350
And then we have our other component, which we saw in the slideshow, and that is our data component.

35
00:02:59,350 --> 00:03:01,780
So we want a way to access and set our data.

36
00:03:01,780 --> 00:03:08,740
And so I'm going to make this together and put the ampersand there and all that data.

37
00:03:08,830 --> 00:03:14,560
So if you are not encountered this before, by putting an ampersand, we are able to have this function

38
00:03:14,800 --> 00:03:17,650
as a setter and together in one.

39
00:03:18,520 --> 00:03:20,350
But that might have been gone over already.

40
00:03:21,820 --> 00:03:24,460
And let's go ahead and make the members.

41
00:03:24,700 --> 00:03:25,960
So we have our data.

42
00:03:25,960 --> 00:03:27,580
I'm just going to underscore data.

43
00:03:29,140 --> 00:03:33,100
And then we are going to have our next pointer.

44
00:03:33,250 --> 00:03:38,350
So that's one node and L.A. pointer, and I'm going to do call that underscore next.

45
00:03:41,440 --> 00:03:48,400
So let's go ahead and move on to the implementation and we'll see exactly what we're going to do with

46
00:03:48,400 --> 00:03:50,360
these next pointers.

47
00:03:50,380 --> 00:03:52,480
It's pretty simple, but.

48
00:03:54,790 --> 00:04:02,560
All right, so let's do a source, file my call this download step.

49
00:04:05,120 --> 00:04:15,440
And of course, we want to include our header, so I'm going to do that first and I'm going to do namespace

50
00:04:16,880 --> 00:04:17,220
STD.

51
00:04:19,790 --> 00:04:21,680
And here's our constructor.

52
00:04:22,610 --> 00:04:31,490
And so as I mentioned in the slideshow, we are going to set our next pointer to null in the beginning.

53
00:04:31,490 --> 00:04:32,240
No point here

54
00:04:35,150 --> 00:04:37,040
and you'll see in a bit.

55
00:04:37,130 --> 00:04:46,490
And how similarly to how I explained in the slide show, it is nice to have it is null pointer so we

56
00:04:46,490 --> 00:04:53,510
can check against that to make sure that we're not going off the end of our link list or and or trying

57
00:04:53,510 --> 00:04:58,100
to reference some random area of memory or something like that.

58
00:04:59,900 --> 00:05:07,010
OK, so I'm also going to put data equal to zero to start that off.

59
00:05:08,990 --> 00:05:10,510
So let's make this first.

60
00:05:12,650 --> 00:05:18,950
Next function, this is going to return the node pointer.

61
00:05:20,900 --> 00:05:29,600
And so what we are going to do is just return that next value.

62
00:05:31,020 --> 00:05:39,030
So this will be our getter, essentially for a node next pointer.

63
00:05:41,990 --> 00:05:44,750
OK, well, I want this to be Boyd.

64
00:05:45,210 --> 00:05:49,870
And this is just going to be the setter.

65
00:05:51,240 --> 00:05:53,250
So I'm going to

66
00:05:57,780 --> 00:06:00,180
pass this next value in there.

67
00:06:02,490 --> 00:06:12,120
And then we will just be setting our private data member next equal to this past value next.

68
00:06:14,370 --> 00:06:19,980
And then the last thing to do is to put our data.

69
00:06:23,460 --> 00:06:31,380
Part of it is this will be our surrogate here for the data, and all we're going to do is return data,

70
00:06:33,150 --> 00:06:33,870
and that's it.

71
00:06:34,560 --> 00:06:35,790
Not a whole lot going on.

72
00:06:36,930 --> 00:06:39,750
We have all the basic things that we need now.

73
00:06:40,560 --> 00:06:48,570
And yeah, as I've actually you can see, I'm just going to make it link list of integers for our data

74
00:06:48,570 --> 00:06:49,080
component.

75
00:06:49,260 --> 00:06:51,810
It's just going to be a simple, simple link list of numbers there.

76
00:06:52,950 --> 00:06:57,600
So I'm going to go ahead and make the link to this file now.

77
00:06:58,770 --> 00:07:02,670
Both those files little English class, so I'm going to make a header.

78
00:07:03,360 --> 00:07:05,340
I'm just going to call this list.

79
00:07:08,700 --> 00:07:09,230
OK.

80
00:07:10,850 --> 00:07:14,420
So let's go ahead and define a class

81
00:07:17,660 --> 00:07:22,340
and then in our public section and the constructor, of course.

82
00:07:23,420 --> 00:07:30,320
And so the two functions that we're going to do to make this as simple as possible is we need a function

83
00:07:30,320 --> 00:07:32,090
to add stuff to our linguist.

84
00:07:32,960 --> 00:07:39,520
And so I'm just going to make a function that appends items to the end of the linked list.

85
00:07:39,530 --> 00:07:42,710
It's just adding items to the end of the link list, basically.

86
00:07:43,550 --> 00:07:53,030
And later on, we'll look at the operations of inserting into a link list and some arbitrary position,

87
00:07:53,030 --> 00:07:59,960
kind of like we talked about in the lecture, and we will maybe add things to the front like pre spending

88
00:08:00,560 --> 00:08:01,130
items.

89
00:08:01,130 --> 00:08:07,010
And then besides that, we the only other function we're really interested in right now is just a print

90
00:08:07,010 --> 00:08:12,500
function that will move through the link list and print out all the values so we can see that we successfully

91
00:08:12,500 --> 00:08:15,710
created a link list and we're able to add them correctly.

92
00:08:16,850 --> 00:08:20,810
So I'm going to start out with this function of adding them to the end, and I'm just going to call

93
00:08:20,810 --> 00:08:24,350
it append rather than add.

94
00:08:25,400 --> 00:08:33,200
And I'm just going to call this data Val for the integer that is passed that you want to add to the

95
00:08:33,200 --> 00:08:33,680
list.

96
00:08:35,570 --> 00:08:42,860
And then I'm just going to call this pin function print p void function as well.

97
00:08:44,960 --> 00:08:55,160
And then as we mentioned in the slideshow, I'm going to want and a pointer and node pointer for head

98
00:08:55,160 --> 00:08:55,940
and tail.

99
00:08:57,140 --> 00:09:05,510
So this keeps track of the first node in the list and the last node in the list, and it's asking me

100
00:09:05,510 --> 00:09:10,370
to add that L node class here.

101
00:09:12,130 --> 00:09:18,400
So I am going to add that I'm president alternator, but it didn't seem to work, so

102
00:09:21,520 --> 00:09:22,870
I'm just going to add that there.

103
00:09:25,730 --> 00:09:32,660
And then we're going to also want to keep track of the size of the linked list, so I'm going to put

104
00:09:32,660 --> 00:09:41,420
a member variable here for the size of the list as well and.

105
00:09:43,440 --> 00:09:46,470
I don't really it probably would be good to put a.

106
00:09:48,860 --> 00:09:51,800
Getter function for size.

107
00:09:52,430 --> 00:09:56,930
But, you know, I'm just going to tell you that right now we can add that if we end up needing that,

108
00:09:56,930 --> 00:09:57,830
but I don't think that.

109
00:09:59,110 --> 00:10:05,920
Not sure where they're actually going to want that right now, but next thing to do is do the implementation,

110
00:10:05,930 --> 00:10:11,230
so let's go ahead and supervise sort of source file.

111
00:10:12,250 --> 00:10:13,990
Won't you list us Rippy?

112
00:10:15,900 --> 00:10:16,340
OK.

113
00:10:17,790 --> 00:10:22,320
So I'm definitely going to want to include our header.

114
00:10:30,940 --> 00:10:35,720
And we're also going to want to include the well-known class.

115
00:10:36,340 --> 00:10:36,490
Right,

116
00:10:40,410 --> 00:10:43,520
well, it's OK.

117
00:10:44,590 --> 00:10:49,180
And since we're printing, we should include I stream.

118
00:10:51,280 --> 00:10:55,330
And I'm also going to you using space as well.

119
00:10:56,830 --> 00:10:58,620
So let's make the constructor, of course.

120
00:11:01,510 --> 00:11:08,310
And just like we did with our next pointer in the node class, we are going to set our node pointers

121
00:11:08,330 --> 00:11:13,900
head and tail equal to null pointer as well.

122
00:11:15,520 --> 00:11:18,370
And size equal to zero.

123
00:11:21,040 --> 00:11:24,940
So I want to jump right into this append function.

124
00:11:37,150 --> 00:11:45,040
All right, so the first thing that we're going to want to do is, of course, create a new node to

125
00:11:45,070 --> 00:11:46,510
put in our list.

126
00:11:48,760 --> 00:11:57,160
So let's go ahead and do that and put a little comment here and say create a new node and set the data

127
00:11:57,160 --> 00:11:58,300
member as well.

128
00:12:01,630 --> 00:12:04,510
So to do that, we'll just be L Node.

129
00:12:05,620 --> 00:12:10,780
Call this new node and then we're going to dynamically allocate this.

130
00:12:13,720 --> 00:12:21,340
So it's going to be a new node pointer, and I'm immediately just going to set the data value right

131
00:12:21,340 --> 00:12:26,410
now equal to the past data.

132
00:12:26,750 --> 00:12:28,810
Well, we want to add to our list.

133
00:12:31,390 --> 00:12:32,020
So.

134
00:12:33,110 --> 00:12:42,050
For any new value to the end, we actually have kind of three cases that are going to be different.

135
00:12:42,620 --> 00:12:45,980
We have the case in which the list is empty.

136
00:12:47,210 --> 00:12:51,410
We have a different case in which the size is one.

137
00:12:52,430 --> 00:12:57,470
And then we have a third case in which the size is anything greater than one.

138
00:12:58,930 --> 00:13:07,600
And we'll see why we need these three different cases here, so I'm going to put if the list is empty

139
00:13:09,400 --> 00:13:21,640
and so that's going to be if the size variable is equal to zero in this case, our head and our tail

140
00:13:22,180 --> 00:13:29,200
are going to be the same because we only have one node that we're adding, which is our new node, then

141
00:13:29,380 --> 00:13:33,790
we only have the option for the head in the tail to be the same thing.

142
00:13:34,630 --> 00:13:44,110
So I'm going to say an equal tail equals new node because those are both node pointers and our new node

143
00:13:44,110 --> 00:13:45,560
is also a node pointer.

144
00:13:47,350 --> 00:13:49,330
And then I'm going to increase the size.

145
00:13:49,330 --> 00:13:51,580
So I'm going to say, I'm going to say size.

146
00:13:52,720 --> 00:13:55,680
I can just say size plus based on the same size possible form.

147
00:13:58,330 --> 00:14:01,240
And then I have this other condition here.

148
00:14:01,240 --> 00:14:02,460
Actually, let me put a comment.

149
00:14:02,470 --> 00:14:11,530
So this is if the size of the list is one and let's say elseif

150
00:14:14,200 --> 00:14:15,940
size equals one.

151
00:14:20,300 --> 00:14:26,690
And this is actually going to be very similar to if the size is anything greater than one, except that

152
00:14:27,080 --> 00:14:38,270
we're just going to want to set our head pointer our head, sorry, our heads next pointer to the new

153
00:14:38,270 --> 00:14:40,580
node because we know that our.

154
00:14:41,600 --> 00:14:47,510
Head is we only have one value, and we're adding the second one.

155
00:14:48,050 --> 00:14:53,510
And so we're just going to be able to update our head pointer like that instead.

156
00:14:53,510 --> 00:14:59,030
If we were add something adding a node later on, like, let's say, it had three values already in

157
00:14:59,030 --> 00:15:01,160
it or sorry, even just two values.

158
00:15:02,120 --> 00:15:09,010
We wouldn't really need to update our head pointer because we're just adding that third value.

159
00:15:09,020 --> 00:15:12,890
We're not really doing anything that should change the head pointer.

160
00:15:13,880 --> 00:15:15,830
So I'm going to say head

161
00:15:18,290 --> 00:15:20,240
arrow next.

162
00:15:21,110 --> 00:15:22,370
And then new node.

163
00:15:24,770 --> 00:15:26,810
And so this is our.

164
00:15:28,360 --> 00:15:34,360
Node classes next function that is the center there.

165
00:15:34,660 --> 00:15:39,850
So if we go back to L.A. CP, it's this one right here.

166
00:15:40,810 --> 00:15:46,120
We are calling this function and passing a new node pointer to it.

167
00:15:47,500 --> 00:15:55,060
So that's what we're using on this line, 28 right here, and then we're going to say tail equals new

168
00:15:55,060 --> 00:15:57,030
note because now we have two nodes.

169
00:15:59,620 --> 00:16:06,220
We said our heads next to that and we're going to have the tail be the latest node that we just added.

170
00:16:08,380 --> 00:16:11,020
So and then tails next.

171
00:16:11,890 --> 00:16:16,040
Just so to point that out again, tails next was said to no pointer.

172
00:16:16,060 --> 00:16:19,690
So that's what tail is.

173
00:16:20,080 --> 00:16:21,130
Tails next pointer is.

174
00:16:22,870 --> 00:16:31,480
So now for the no last option, we're going to have to move through our list to the last node in the

175
00:16:31,480 --> 00:16:34,030
list so that we can successfully add it to the end.

176
00:16:35,590 --> 00:16:42,970
So I'm going to say move through list and add new node to the end.

177
00:16:44,580 --> 00:16:45,400
And so this is going to be.

178
00:16:46,990 --> 00:16:53,140
So anything basically the case that it's not either of these two conditions.

179
00:16:55,390 --> 00:17:01,720
And so to do this, to move through the list, what we're going to do is we're going to create a temporary

180
00:17:01,720 --> 00:17:04,510
pointer that starts at the head.

181
00:17:05,440 --> 00:17:07,290
So it's going to be equal to the head pointer.

182
00:17:07,690 --> 00:17:12,550
Someone declare a new node pointer pointer and we call this curve for current.

183
00:17:13,600 --> 00:17:15,100
And I say equals head.

184
00:17:15,340 --> 00:17:19,930
So it starts out as the head and then we're going to want to loop through.

185
00:17:21,140 --> 00:17:26,420
Until we get to the very end and then we're going, I want to add our new value there.

186
00:17:28,100 --> 00:17:34,400
And so what I'm going to do actually is I'm going to say, Wow, this current pointer is actually not

187
00:17:34,400 --> 00:17:40,820
equal to no point here because I know if it's equal to no pointer, then that means that I've gone off

188
00:17:40,820 --> 00:17:41,330
the end.

189
00:17:42,860 --> 00:17:50,540
Like I kept going and kept referencing the next pointer going on and on until I got to a point where

190
00:17:50,540 --> 00:17:51,350
I was off the list.

191
00:17:51,350 --> 00:17:54,560
And now I was at no point here because the.

192
00:17:57,780 --> 00:18:05,070
The last items next pointer to the last nodes next pointer, it's going to be pointing to null.

193
00:18:05,490 --> 00:18:08,670
So if I went off the end, I'd be in pointer.

194
00:18:10,410 --> 00:18:18,180
So then I'm going to put a condition and I'm going to say if turns next is in fact null pointer.

195
00:18:18,870 --> 00:18:20,520
And this is our getter here.

196
00:18:21,580 --> 00:18:26,830
The one where we hear let me just jump back here, so we're calling this right now.

197
00:18:29,150 --> 00:18:31,370
And I must say, if that's equal to null pointer,

198
00:18:34,670 --> 00:18:38,990
then I'm going to say that it's next.

199
00:18:40,190 --> 00:18:45,680
And now I'm going to use this other next function, the one that we used on this line.

200
00:18:45,680 --> 00:18:52,070
28 here I'm going to say that is going to be new node.

201
00:18:54,050 --> 00:18:56,300
So we're just connecting things with pointers here.

202
00:18:57,470 --> 00:19:02,810
It's really all that's going on, and I'm going to update my tale now to that, you know, just like

203
00:19:02,810 --> 00:19:05,420
if we just like we did in both of these.

204
00:19:06,550 --> 00:19:07,540
Conditions up here.

205
00:19:08,800 --> 00:19:16,270
And if that's the case, I've already added that I don't even need to do anything else in this loop

206
00:19:16,270 --> 00:19:18,990
at that at this point in this condition, if that's been met.

207
00:19:19,000 --> 00:19:23,560
So I'm just going to actually return because we don't even need to do anything else in the function

208
00:19:23,560 --> 00:19:24,070
at this point.

209
00:19:26,290 --> 00:19:29,680
And then the last thing this is really what it does.

210
00:19:29,680 --> 00:19:31,750
All the work here, this line right here.

211
00:19:31,760 --> 00:19:40,210
So I'm saying current equals cur arrow next strike her equals her arrow next.

212
00:19:40,450 --> 00:19:45,400
And so this is our getter in what we're doing here is essentially moving the current.

213
00:19:46,660 --> 00:19:55,870
Pointers, so it is a known pointer, but we can also think of this as like a a pointer just kind of

214
00:19:55,870 --> 00:19:58,480
iterating through our list like an iterator.

215
00:19:59,440 --> 00:20:02,440
So this is how you move it to the next item.

216
00:20:02,470 --> 00:20:07,720
This is essentially what is driving our sequential movement through the linked list.

217
00:20:10,040 --> 00:20:14,150
And that should be good for the pin function.

218
00:20:15,610 --> 00:20:18,200
I'm just going to leave it pretty basic now.

219
00:20:18,860 --> 00:20:24,770
We said we aren't really doing a whole lot except just trying to prove that we can get this thing working.

220
00:20:26,330 --> 00:20:28,910
OK, so let me add this print function now.

221
00:20:32,030 --> 00:20:35,810
So we're going to essentially do the same exact thing that we did.

222
00:20:37,050 --> 00:20:38,190
Right here.

223
00:20:40,690 --> 00:20:45,640
Moving through the list instead of adding things, we're just going to be printing them out, of course.

224
00:20:45,640 --> 00:20:52,840
So I'm going to say look through the list and print out these values.

225
00:20:54,460 --> 00:20:59,950
So let's go ahead and make another current point here, and I'm going to do the same thing and just

226
00:20:59,950 --> 00:21:01,470
call it Carrier said equal ahead.

227
00:21:01,480 --> 00:21:05,030
So we started at the beginning and then make this other while live.

228
00:21:05,320 --> 00:21:06,490
It's exactly the same.

229
00:21:07,450 --> 00:21:13,050
I really could just copy it, but I'm just going to tape it and I'm going to say it's good.

230
00:21:13,400 --> 00:21:14,890
Let's not equal null pointer.

231
00:21:16,300 --> 00:21:24,400
And then all we're going to do is print out our data so I can call that function here.

232
00:21:26,320 --> 00:21:28,600
So we're calling that same function.

233
00:21:31,580 --> 00:21:33,530
Here is where we said it.

234
00:21:35,180 --> 00:21:38,560
It's probably something I should have mentioned if you haven't done this before, this is also going

235
00:21:38,560 --> 00:21:46,720
to be the syntax for using that setter getter where we put the ampersand reference in front of it.

236
00:21:49,040 --> 00:21:51,980
So basically when you.

237
00:21:53,200 --> 00:22:00,160
Said it and get it is kind of the same syntax, so here we set it equal to something we're calling it

238
00:22:00,160 --> 00:22:02,620
and then putting the assignment operator.

239
00:22:04,490 --> 00:22:08,590
And then down here, we're just calling it, and that's giving us what we want, so we could, you know,

240
00:22:08,600 --> 00:22:12,770
if we wanted to say something else equal to it, we would just be like putting the assignment right

241
00:22:12,770 --> 00:22:14,180
here and add some variable.

242
00:22:17,420 --> 00:22:18,510
But you might argue know that.

243
00:22:18,590 --> 00:22:21,170
So of that, if that's something that you're already familiar with.

244
00:22:22,100 --> 00:22:30,920
And I'm also going to add a little arrow here, just so it just kind of makes a little extra sense visibly

245
00:22:30,920 --> 00:22:33,050
if that means anything to you.

246
00:22:33,480 --> 00:22:38,450
But yeah, these will just be like you can imagine these as our pointers chaining them together.

247
00:22:38,570 --> 00:22:43,190
So I'm going to print this out and I'll just kind of be in a line so we can see what our link list looks

248
00:22:43,190 --> 00:22:43,490
like.

249
00:22:44,450 --> 00:22:49,670
And then, of course, I'm going to want to add this line that really drives it, which is the curve

250
00:22:49,680 --> 00:22:52,190
equals K Arrow next.

251
00:22:55,820 --> 00:23:02,210
And then after this, I'll go ahead and just print out a new line there.

252
00:23:03,290 --> 00:23:05,990
OK, so that is actually all we're going to put here.

253
00:23:07,600 --> 00:23:09,910
Well, go ahead and save this.

254
00:23:11,110 --> 00:23:18,910
And then let's go to our client code that is going to be our driver program for this.

255
00:23:20,700 --> 00:23:29,040
So I think that what I'm actually going to do is just have a stake in some.

256
00:23:31,490 --> 00:23:40,820
Input from a file, so I'm going to go ahead and include the stream library there

257
00:23:44,090 --> 00:23:47,930
and then of course, what else do we have to include our.

258
00:23:52,020 --> 00:23:52,920
Header file.

259
00:23:55,890 --> 00:24:00,030
And yeah, I think that's all we really need.

260
00:24:03,750 --> 00:24:06,850
I think I need the known class.

261
00:24:06,870 --> 00:24:15,930
OK, so for that, of course, I'm going to want to put some command line answer to this, which we

262
00:24:15,930 --> 00:24:25,830
will just be doing in our edit configurations for Sea Lion, but we don't want that.

263
00:24:28,140 --> 00:24:38,540
And then let's do a little check here to make sure that the users actually enter into arguments.

264
00:24:38,550 --> 00:24:41,840
Of course, we won't be using the terminal for this.

265
00:24:41,850 --> 00:24:46,590
We're just going to run it and sea lion, but still want to put it here.

266
00:24:47,160 --> 00:24:50,730
OK, yes, we did want to run it differently.

267
00:24:50,730 --> 00:25:01,320
So I'm going to say usage and put our executable here are in V0.

268
00:25:03,240 --> 00:25:08,250
And then say you should do that and then put the name of the entire file

269
00:25:12,270 --> 00:25:17,280
just a little error message there in case there is no argument for an input file.

270
00:25:19,080 --> 00:25:23,880
OK, so I'm going to stand Ireland to list here.

271
00:25:24,300 --> 00:25:36,090
I'm just going to call it link to list equals new list and then we'll declare our stream here

272
00:25:38,870 --> 00:25:40,860
and call this list stream.

273
00:25:43,260 --> 00:25:49,950
And then we will open our stream and then we'll make a variable for our data and then we'll just take

274
00:25:49,950 --> 00:25:50,760
it in a loop.

275
00:25:51,300 --> 00:25:57,210
So up to this stream, open

276
00:25:59,790 --> 00:26:02,370
the one place and

277
00:26:05,520 --> 00:26:10,200
to load data variable there to take in the integers.

278
00:26:10,210 --> 00:26:23,400
And I'm going to say, well, this stream input data and we're going to say linked list and then we're

279
00:26:23,400 --> 00:26:31,890
going to color append function and we're going to put that data value that we're reading from the file.

280
00:26:32,300 --> 00:26:34,980
And so we're passing that here.

281
00:26:37,030 --> 00:26:41,170
And then we're creating our new node and then setting that data value right here and then, of course,

282
00:26:41,170 --> 00:26:43,000
the rest of the function that we're already aware of.

283
00:26:46,480 --> 00:26:46,820
All right.

284
00:26:46,840 --> 00:26:51,790
And then once that's done, I'm just going to want to go ahead and call the print function on my linked

285
00:26:51,790 --> 00:26:52,180
list

286
00:26:56,500 --> 00:26:58,930
so we can see that we vetted everything correctly.

287
00:26:59,590 --> 00:27:02,260
And so at this point, I probably should add an input file.

288
00:27:02,260 --> 00:27:08,320
So let me just go here, I'm going to make a new file and I'm just going to call this and put.

289
00:27:11,390 --> 00:27:11,950
Let's see.

290
00:27:14,430 --> 00:27:17,640
Text file, yes, I should have said and put that text, he.

291
00:27:20,390 --> 00:27:20,840
All right.

292
00:27:21,140 --> 00:27:22,010
So.

293
00:27:25,740 --> 00:27:26,490
Like that?

294
00:27:28,450 --> 00:27:28,750
Yeah.

295
00:27:29,710 --> 00:27:36,490
So I'm just going to do like something like that one through seven.

296
00:27:37,600 --> 00:27:47,140
So you go ahead and say this and let's go back to Maine and then we want to set our.

297
00:27:48,340 --> 00:27:50,210
Make sure everything looks good.

298
00:27:50,620 --> 00:27:51,700
Go ahead and.

299
00:27:53,620 --> 00:27:55,960
Said this in the edit configurations.

300
00:27:57,430 --> 00:27:58,060
So.

301
00:28:01,670 --> 00:28:08,120
And put that to me, and then I'm going to set my working directory here.

302
00:28:10,370 --> 00:28:12,890
Simple, singly linked list.

303
00:28:14,610 --> 00:28:15,120
OK.

304
00:28:16,440 --> 00:28:19,800
So that all be set up to play.

305
00:28:21,940 --> 00:28:23,500
And then let's see if it runs.

306
00:28:25,050 --> 00:28:26,820
So go ahead and right now.

307
00:28:30,510 --> 00:28:30,690
OK.

308
00:28:30,850 --> 00:28:31,190
No.

309
00:28:31,430 --> 00:28:34,270
Did not run what seems to be the problem.

310
00:28:34,300 --> 00:28:35,830
I think that maybe.

311
00:28:37,370 --> 00:28:40,760
You know what I'm going to add, I think it's actually just inputs.

312
00:28:43,770 --> 00:28:48,510
Don't actually have the extension on there, so let's do this.

313
00:28:52,630 --> 00:28:53,080
OK.

314
00:28:53,170 --> 00:28:57,010
So did not successfully add the.

315
00:28:58,220 --> 00:29:00,110
Items to the linked list.

316
00:29:05,510 --> 00:29:09,740
So let's figure out what the problem is.

317
00:29:17,760 --> 00:29:23,850
Let's go to our link list implementation here for the append function.

318
00:29:31,570 --> 00:29:32,170
Just.

319
00:29:39,040 --> 00:29:40,710
Let's just see some.

320
00:29:44,110 --> 00:29:46,750
Let's just do some D.

321
00:29:49,050 --> 00:29:49,800
Bugging.

322
00:29:51,650 --> 00:29:52,190
So.

323
00:30:00,730 --> 00:30:03,430
Head size of continue.

324
00:30:07,230 --> 00:30:10,650
So tell us one.

325
00:30:13,750 --> 00:30:15,420
They do value three.

326
00:30:18,620 --> 00:30:20,780
So let's just go ahead and step through this year.

327
00:30:28,300 --> 00:30:28,820
Aha!

328
00:30:28,870 --> 00:30:31,240
We did not update our size.

329
00:30:31,570 --> 00:30:32,590
That is the problem.

330
00:30:38,240 --> 00:30:41,090
OK, so we're going to want to add.

331
00:30:44,190 --> 00:30:46,770
Definitely going to want to make sure to update our.

332
00:30:48,770 --> 00:30:50,100
Size of our blank list.

333
00:30:50,120 --> 00:30:53,720
We never did that here and in there, either, so

334
00:30:56,930 --> 00:30:58,490
size plus equals one.

335
00:31:00,080 --> 00:31:06,810
And in here, we also want to do that as well, so we successfully at A..

336
00:31:09,130 --> 00:31:11,420
Size, think of one.

337
00:31:12,860 --> 00:31:13,250
OK.

338
00:31:14,030 --> 00:31:15,680
So hopefully that fixes our problem.

339
00:31:16,100 --> 00:31:17,140
Sorry for the delay there.

340
00:31:17,150 --> 00:31:21,950
Sometimes I think that getting errors on it, though, is kind of nice.

341
00:31:23,900 --> 00:31:27,920
Just as a chance to go through the debugger and, you know.

342
00:31:29,350 --> 00:31:35,960
It's just naturally, it airs on a lot of things, so it's good to kind of walk through it, and debugging

343
00:31:35,960 --> 00:31:40,760
is definitely one of the most valuable skills, so sometimes it's a benefit.

344
00:31:42,830 --> 00:31:46,730
So let's run this, and yet that looks like it's pretty nice.

345
00:31:47,570 --> 00:31:53,210
One two three four five six seven And we see our little corners there that we print out as well.

346
00:31:54,830 --> 00:31:58,850
So like I said, this is just a really basic link list implementation.

347
00:31:59,300 --> 00:32:00,810
There are a few different ways you can do it.

348
00:32:00,830 --> 00:32:03,980
You, of course, can use a struct for your node.

349
00:32:05,120 --> 00:32:12,020
And I definitely encourage you to go online and kind of see what other people have done for implementing

350
00:32:12,020 --> 00:32:18,560
link lists and just use the style that you're comfortable, comfortable with and whatever makes sense

351
00:32:18,560 --> 00:32:19,110
to you.

352
00:32:19,640 --> 00:32:24,740
Everyone has their own programming style, and of course, you get used to the coding style and code

353
00:32:24,740 --> 00:32:27,470
base of whatever place you might end up working at.

354
00:32:27,950 --> 00:32:30,500
So it's good to look at different ways of doing it.

355
00:32:32,090 --> 00:32:38,600
And then in the next video, we will hopefully get into maybe changing this into a link list and then

356
00:32:38,600 --> 00:32:43,850
add some more stuff that we should have, like copy constructors, assignment operators, things like

357
00:32:43,850 --> 00:32:51,680
that, because this is really just a super basic implementation of a link list just to just to, like,

358
00:32:51,680 --> 00:32:52,610
ease into it.

359
00:32:52,910 --> 00:32:58,160
So everything makes sense before we start adding all the bells and whistles and everything like that.

360
00:32:59,090 --> 00:33:05,030
OK, so I hope this was educational for you, and I will see you in the next video.
