1
00:00:00,360 --> 00:00:01,590
Hello, my name is Stephanie.

2
00:00:01,590 --> 00:00:03,510
Welcome to another lecture of our course.

3
00:00:03,540 --> 00:00:06,930
In this lecture of our course, you will learn about the nodes here.

4
00:00:19,750 --> 00:00:26,920
The Nord is a basic building of many data structures which we will learn in this course.

5
00:00:26,920 --> 00:00:34,030
So Node has two functions, Node has two functions.

6
00:00:34,540 --> 00:00:36,910
The first function is that.

7
00:00:39,330 --> 00:00:39,720
It.

8
00:00:39,930 --> 00:00:41,200
It holds a piece of data.

9
00:00:41,220 --> 00:00:45,870
The first function holds a piece of data also known as value.

10
00:00:48,220 --> 00:00:54,850
The second function is that the connectivity between another node and itself using an object reference

11
00:00:54,850 --> 00:00:55,660
operator.

12
00:00:55,750 --> 00:01:00,160
Another reference pointer, also known as the next year.

13
00:01:00,190 --> 00:01:00,880
The.

14
00:01:01,820 --> 00:01:03,230
Next pointer.

15
00:01:07,560 --> 00:01:17,160
Peter So based on this explanation, we can create a node datatype in C plus plus here.

16
00:01:17,160 --> 00:01:21,420
So firstly, let's actually make this like that here.

17
00:01:21,420 --> 00:01:22,080
Yes.

18
00:01:24,910 --> 00:01:25,330
Oops.

19
00:01:25,330 --> 00:01:25,840
Yeah.

20
00:01:26,830 --> 00:01:31,590
Make it here and let's create a node here in real life.

21
00:01:31,600 --> 00:01:32,570
In Cplusplus here.

22
00:01:32,590 --> 00:01:33,970
So firstly.

23
00:01:34,910 --> 00:01:37,160
We first need to create a class node.

24
00:01:37,190 --> 00:01:42,530
Here the class node and we will define oops.

25
00:01:42,530 --> 00:01:42,890
Yeah.

26
00:01:42,920 --> 00:01:44,150
Class node.

27
00:01:44,180 --> 00:01:44,630
Here we will.

28
00:01:44,630 --> 00:01:47,460
Inside this node we will create a two public variables.

29
00:01:47,480 --> 00:01:54,080
The first is integer value and next is a node pointer, which is the next pointer.

30
00:01:54,470 --> 00:01:58,760
As you can see here, the next pointer.

31
00:01:59,150 --> 00:02:03,320
So node pointer and next.

32
00:02:05,010 --> 00:02:08,190
So we will also use this diagram here.

33
00:02:08,190 --> 00:02:10,080
We will here.

34
00:02:10,080 --> 00:02:11,790
Let's actually create the diagram.

35
00:02:13,050 --> 00:02:22,830
This is our diagram, which in left side we would have the value value.

36
00:02:28,340 --> 00:02:31,820
In the right side we will have next.

37
00:02:37,750 --> 00:02:38,140
Here.

38
00:02:38,530 --> 00:02:46,210
So now let's create three single nodes using the new the new node data type.

39
00:02:46,210 --> 00:02:55,380
So the nodes will contain values of five, ten and 25 or 5, 10 or 29, for example.

40
00:02:55,390 --> 00:02:57,610
So here we will create a node.

41
00:03:00,070 --> 00:03:03,490
So, for example, in this case, it's going to be node one.

42
00:03:04,530 --> 00:03:05,640
Node one.

43
00:03:06,160 --> 00:03:07,440
Node one.

44
00:03:07,830 --> 00:03:08,940
The new Node.

45
00:03:08,970 --> 00:03:09,720
New node.

46
00:03:09,750 --> 00:03:12,570
Here we will also create the actual node one.

47
00:03:13,320 --> 00:03:14,670
Node one.

48
00:03:15,180 --> 00:03:17,430
Here assign it to value.

49
00:03:17,850 --> 00:03:20,190
The first value in node one is going to be.

50
00:03:21,130 --> 00:03:21,580
As I said.

51
00:03:21,580 --> 00:03:21,810
Yeah.

52
00:03:21,820 --> 00:03:25,090
Five and let's create a Node two here.

53
00:03:25,120 --> 00:03:27,700
Node Node two.

54
00:03:27,700 --> 00:03:28,930
New node here.

55
00:03:30,300 --> 00:03:32,700
And Node two value is going to be.

56
00:03:34,150 --> 00:03:35,080
Value.

57
00:03:36,600 --> 00:03:37,950
It's going to be, as I said.

58
00:03:37,970 --> 00:03:38,120
Yeah.

59
00:03:38,160 --> 00:03:40,110
20 for example.

60
00:03:40,110 --> 00:03:41,490
And note three here.

61
00:03:41,490 --> 00:03:43,080
Let's create note three here.

62
00:03:43,080 --> 00:03:46,260
Note a note three.

63
00:03:47,400 --> 00:03:47,970
New.

64
00:03:47,970 --> 00:03:49,110
Not here.

65
00:03:50,080 --> 00:03:52,150
And the node three value.

66
00:03:52,510 --> 00:03:57,160
Node three value is going to be 29.

67
00:03:58,000 --> 00:04:03,700
So now that since we don't initialize the next pointer for all nodes, it will be automatically filled

68
00:04:03,700 --> 00:04:06,070
with the null pointer.

69
00:04:06,070 --> 00:04:12,490
So all of these here actually let's make it like that that you would understand.

70
00:04:12,700 --> 00:04:16,270
Everyone will understand here that here.

71
00:04:18,850 --> 00:04:20,680
We will delete this.

72
00:04:21,490 --> 00:04:22,630
We previously created.

73
00:04:23,560 --> 00:04:24,040
Here.

74
00:04:24,040 --> 00:04:27,830
Now, we will make a diagram for the nodes.

75
00:04:27,850 --> 00:04:29,230
So here.

76
00:04:33,280 --> 00:04:33,850
Here.

77
00:04:34,030 --> 00:04:38,260
So now we will drive some items to it.

78
00:04:38,530 --> 00:04:39,850
So we have three nodes.

79
00:04:39,850 --> 00:04:43,690
We will have three rows here and two columns.

80
00:04:46,200 --> 00:04:46,860
Here.

81
00:04:55,840 --> 00:04:56,320
Here.

82
00:04:56,620 --> 00:04:59,460
So we will also need to create a rose here.

83
00:04:59,470 --> 00:05:00,190
One.

84
00:05:01,840 --> 00:05:03,880
Two and three for now.

85
00:05:04,000 --> 00:05:04,840
Three is okay.

86
00:05:04,840 --> 00:05:08,020
And here the in the left side of our node.

87
00:05:08,050 --> 00:05:10,750
We have five here.

88
00:05:11,400 --> 00:05:12,240
Five.

89
00:05:12,240 --> 00:05:14,790
And then we have the 20.

90
00:05:16,500 --> 00:05:17,640
Oops 20.

91
00:05:17,970 --> 00:05:20,460
Then we have 29.

92
00:05:21,360 --> 00:05:22,200
29.

93
00:05:23,610 --> 00:05:27,420
But here we all have noodles.

94
00:05:27,420 --> 00:05:30,060
So here we have noodle.

95
00:05:32,400 --> 00:05:33,360
Newell.

96
00:05:33,930 --> 00:05:35,610
Here we have new.

97
00:05:38,610 --> 00:05:44,970
And also over here we have NULL because we haven't assigned our next pointers yet.

98
00:05:45,560 --> 00:05:46,220
Here.

99
00:05:46,400 --> 00:05:54,840
So now it's time to connect the these three nodes so that it becomes a node chain.

100
00:05:54,860 --> 00:06:01,580
So we will set the next pointers of node one node to object, and we will also set the next pointer

101
00:06:01,610 --> 00:06:02,390
of.

102
00:06:03,790 --> 00:06:05,500
The not to object here.

103
00:06:06,310 --> 00:06:09,640
And we will we will set here the not to object.

104
00:06:09,640 --> 00:06:11,650
So this is the value one.

105
00:06:11,650 --> 00:06:19,690
So node one here, two here and three here and here.

106
00:06:21,290 --> 00:06:25,070
We will set the next pointer of Node one here.

107
00:06:25,070 --> 00:06:30,500
Actually, yes, we will set the next pointer of node one to.

108
00:06:32,330 --> 00:06:34,370
Let's make it cooler here.

109
00:06:34,370 --> 00:06:37,910
So we will set Node one pointer to Node two.

110
00:06:38,600 --> 00:06:42,080
We will set the next pointer of Node two.

111
00:06:43,510 --> 00:06:46,270
Two node one object here.

112
00:06:48,250 --> 00:06:57,040
And we will keep the next pointer of Node three remain the null here to indicate that it's the end of

113
00:06:57,040 --> 00:06:57,630
the chain.

114
00:06:57,640 --> 00:06:59,200
So the code here.

115
00:07:00,330 --> 00:07:01,530
Well be like that.

116
00:07:01,530 --> 00:07:03,510
So Node one.

117
00:07:03,510 --> 00:07:06,750
Node one actually, let's add command.

118
00:07:09,650 --> 00:07:12,230
Assign next chapter.

119
00:07:12,920 --> 00:07:15,140
And here the node one.

120
00:07:15,170 --> 00:07:16,220
Next here.

121
00:07:16,250 --> 00:07:18,770
Node one Next is going to be node two here.

122
00:07:18,770 --> 00:07:21,590
As I said, Node one to Node two.

123
00:07:23,390 --> 00:07:31,430
Note two and also note two to note two next to note three.

124
00:07:31,670 --> 00:07:37,010
And as you can see here, we did note three to next to note three here.

125
00:07:37,010 --> 00:07:44,240
So by executing this code, the illustration would be like this, exactly like that.

126
00:07:44,330 --> 00:07:46,460
And the note three is going to be new.

127
00:07:46,460 --> 00:07:48,150
But for now it's like it.

128
00:07:48,650 --> 00:07:51,200
They are also new here for now, not null here.

129
00:07:51,200 --> 00:07:58,790
So because our note next pointer here the next pointer of this note.

130
00:07:59,720 --> 00:08:02,480
Points to here.

131
00:08:03,750 --> 00:08:10,230
Note, actually, if you use a different color, this points to note.

132
00:08:20,720 --> 00:08:21,100
Oops.

133
00:08:21,110 --> 00:08:21,650
Yeah.

134
00:08:21,950 --> 00:08:26,690
So this will point to the node to.

135
00:08:29,290 --> 00:08:32,830
And here this will point to the node.

136
00:08:33,700 --> 00:08:34,390
Three.

137
00:08:35,650 --> 00:08:43,030
And here we actually let create the print function print node function.

138
00:08:43,030 --> 00:08:50,710
And we will with this function, we will print these nodes, uh, printed node chain onto the console

139
00:08:50,710 --> 00:08:51,220
here.

140
00:08:51,790 --> 00:09:01,420
Here we will actually, let's, uh, above that, we will create the print void print node function.

141
00:09:01,420 --> 00:09:03,190
And this will take note here.

142
00:09:04,330 --> 00:09:13,810
As a parameter node and here it will print the initial node until it finds a null for the next pointer

143
00:09:13,810 --> 00:09:15,910
that indicates the end of node chain.

144
00:09:15,910 --> 00:09:22,240
So here, while while node is not equal to null.

145
00:09:24,830 --> 00:09:28,250
Then see out note here.

146
00:09:29,180 --> 00:09:40,460
We also need to implement STD here using namespace std and here C out note value.

147
00:09:43,750 --> 00:09:44,950
And here.

148
00:09:46,660 --> 00:09:47,710
North Valley is going to be.

149
00:09:47,740 --> 00:09:49,780
This is illustrated a little bit.

150
00:09:50,380 --> 00:09:53,230
And here this is our node value.

151
00:09:55,920 --> 00:09:58,050
And after that we will note here.

152
00:09:59,050 --> 00:10:01,840
Node equals node next.

153
00:10:06,250 --> 00:10:15,610
And after that we will see out if this after the looping here, we will see out null.

154
00:10:16,880 --> 00:10:17,300
Yeah.

155
00:10:17,720 --> 00:10:19,070
The noodle here.

156
00:10:20,580 --> 00:10:21,840
And end line.

157
00:10:23,270 --> 00:10:24,590
So here.

158
00:10:31,110 --> 00:10:35,190
We printed the we created the print node function here.

159
00:10:35,610 --> 00:10:39,150
Now, as I said here, we derived our diagram.

160
00:10:39,150 --> 00:10:40,940
The nodes will be like this.

161
00:10:40,950 --> 00:10:48,720
And here after that, after assigning the next and values of our nodes, we will print use the print

162
00:10:48,750 --> 00:10:50,130
node function.

163
00:10:50,130 --> 00:10:53,010
So print node node one here.

164
00:10:53,520 --> 00:10:54,240
Yes.

165
00:10:55,700 --> 00:10:59,870
And let's go to the console here, compile our application.

166
00:11:02,420 --> 00:11:07,280
Here plus plus main main dot CPP.

167
00:11:08,800 --> 00:11:09,460
And here.

168
00:11:09,530 --> 00:11:10,240
Ataxia.

169
00:11:13,150 --> 00:11:18,840
And here, as you can see, we got an in the infinite loop here.

170
00:11:18,850 --> 00:11:20,830
So let's break this.

171
00:11:22,080 --> 00:11:23,360
Cialis.

172
00:11:24,120 --> 00:11:25,930
Let's see what happened here.

173
00:11:25,950 --> 00:11:27,810
So we also need to.

174
00:11:28,890 --> 00:11:31,350
Break our while loop at some.

175
00:11:32,490 --> 00:11:33,270
Condition.

176
00:11:34,910 --> 00:11:39,110
So it's going to be like the C out null end line.

177
00:11:39,330 --> 00:11:45,020
The assign the node new node seven 514 here.

178
00:11:48,970 --> 00:11:49,590
Not.

179
00:11:55,530 --> 00:11:56,420
And after we.

180
00:11:56,600 --> 00:11:57,960
We are returning here.

181
00:12:03,980 --> 00:12:10,100
And here after that, if we just ignore this loop here, go to the top of our code here.

182
00:12:10,100 --> 00:12:12,260
And as you can see here.

183
00:12:13,730 --> 00:12:14,210
Oops.

184
00:12:14,340 --> 00:12:15,110
Uh, here.

185
00:12:16,370 --> 00:12:20,510
Let's actually make it run it again and see what happens here.

186
00:12:23,250 --> 00:12:27,690
So dot x here.

187
00:12:29,670 --> 00:12:32,160
And as you can see here, we have firstly.

188
00:12:33,710 --> 00:12:38,060
The new five year as we did here.

189
00:12:38,420 --> 00:12:40,150
So let's get to this here.

190
00:12:40,160 --> 00:12:47,180
So firstly, we have five, then we have 20 and then we have 29.

191
00:12:47,940 --> 00:12:54,690
After that, it's just a null null zero, which is our while loop isn't breaking here and returned anything.

192
00:12:54,690 --> 00:12:59,910
That's why we have seen infinite numbers here and there is no pointers here.

193
00:12:59,910 --> 00:13:04,620
So that's out with our example here and I'm waiting you in next lecture.
