WEBVTT

00:00.360 --> 00:01.590
Hello, my name is Stephanie.

00:01.590 --> 00:03.510
Welcome to another lecture of our course.

00:03.540 --> 00:06.930
In this lecture of our course, you will learn about the nodes here.

00:19.750 --> 00:26.920
The Nord is a basic building of many data structures which we will learn in this course.

00:26.920 --> 00:34.030
So Node has two functions, Node has two functions.

00:34.540 --> 00:36.910
The first function is that.

00:39.330 --> 00:39.720
It.

00:39.930 --> 00:41.200
It holds a piece of data.

00:41.220 --> 00:45.870
The first function holds a piece of data also known as value.

00:48.220 --> 00:54.850
The second function is that the connectivity between another node and itself using an object reference

00:54.850 --> 00:55.660
operator.

00:55.750 --> 01:00.160
Another reference pointer, also known as the next year.

01:00.190 --> 01:00.880
The.

01:01.820 --> 01:03.230
Next pointer.

01:07.560 --> 01:17.160
Peter So based on this explanation, we can create a node datatype in C plus plus here.

01:17.160 --> 01:21.420
So firstly, let's actually make this like that here.

01:21.420 --> 01:22.080
Yes.

01:24.910 --> 01:25.330
Oops.

01:25.330 --> 01:25.840
Yeah.

01:26.830 --> 01:31.590
Make it here and let's create a node here in real life.

01:31.600 --> 01:32.570
In Cplusplus here.

01:32.590 --> 01:33.970
So firstly.

01:34.910 --> 01:37.160
We first need to create a class node.

01:37.190 --> 01:42.530
Here the class node and we will define oops.

01:42.530 --> 01:42.890
Yeah.

01:42.920 --> 01:44.150
Class node.

01:44.180 --> 01:44.630
Here we will.

01:44.630 --> 01:47.460
Inside this node we will create a two public variables.

01:47.480 --> 01:54.080
The first is integer value and next is a node pointer, which is the next pointer.

01:54.470 --> 01:58.760
As you can see here, the next pointer.

01:59.150 --> 02:03.320
So node pointer and next.

02:05.010 --> 02:08.190
So we will also use this diagram here.

02:08.190 --> 02:10.080
We will here.

02:10.080 --> 02:11.790
Let's actually create the diagram.

02:13.050 --> 02:22.830
This is our diagram, which in left side we would have the value value.

02:28.340 --> 02:31.820
In the right side we will have next.

02:37.750 --> 02:38.140
Here.

02:38.530 --> 02:46.210
So now let's create three single nodes using the new the new node data type.

02:46.210 --> 02:55.380
So the nodes will contain values of five, ten and 25 or 5, 10 or 29, for example.

02:55.390 --> 02:57.610
So here we will create a node.

03:00.070 --> 03:03.490
So, for example, in this case, it's going to be node one.

03:04.530 --> 03:05.640
Node one.

03:06.160 --> 03:07.440
Node one.

03:07.830 --> 03:08.940
The new Node.

03:08.970 --> 03:09.720
New node.

03:09.750 --> 03:12.570
Here we will also create the actual node one.

03:13.320 --> 03:14.670
Node one.

03:15.180 --> 03:17.430
Here assign it to value.

03:17.850 --> 03:20.190
The first value in node one is going to be.

03:21.130 --> 03:21.580
As I said.

03:21.580 --> 03:21.810
Yeah.

03:21.820 --> 03:25.090
Five and let's create a Node two here.

03:25.120 --> 03:27.700
Node Node two.

03:27.700 --> 03:28.930
New node here.

03:30.300 --> 03:32.700
And Node two value is going to be.

03:34.150 --> 03:35.080
Value.

03:36.600 --> 03:37.950
It's going to be, as I said.

03:37.970 --> 03:38.120
Yeah.

03:38.160 --> 03:40.110
20 for example.

03:40.110 --> 03:41.490
And note three here.

03:41.490 --> 03:43.080
Let's create note three here.

03:43.080 --> 03:46.260
Note a note three.

03:47.400 --> 03:47.970
New.

03:47.970 --> 03:49.110
Not here.

03:50.080 --> 03:52.150
And the node three value.

03:52.510 --> 03:57.160
Node three value is going to be 29.

03:58.000 --> 04:03.700
So now that since we don't initialize the next pointer for all nodes, it will be automatically filled

04:03.700 --> 04:06.070
with the null pointer.

04:06.070 --> 04:12.490
So all of these here actually let's make it like that that you would understand.

04:12.700 --> 04:16.270
Everyone will understand here that here.

04:18.850 --> 04:20.680
We will delete this.

04:21.490 --> 04:22.630
We previously created.

04:23.560 --> 04:24.040
Here.

04:24.040 --> 04:27.830
Now, we will make a diagram for the nodes.

04:27.850 --> 04:29.230
So here.

04:33.280 --> 04:33.850
Here.

04:34.030 --> 04:38.260
So now we will drive some items to it.

04:38.530 --> 04:39.850
So we have three nodes.

04:39.850 --> 04:43.690
We will have three rows here and two columns.

04:46.200 --> 04:46.860
Here.

04:55.840 --> 04:56.320
Here.

04:56.620 --> 04:59.460
So we will also need to create a rose here.

04:59.470 --> 05:00.190
One.

05:01.840 --> 05:03.880
Two and three for now.

05:04.000 --> 05:04.840
Three is okay.

05:04.840 --> 05:08.020
And here the in the left side of our node.

05:08.050 --> 05:10.750
We have five here.

05:11.400 --> 05:12.240
Five.

05:12.240 --> 05:14.790
And then we have the 20.

05:16.500 --> 05:17.640
Oops 20.

05:17.970 --> 05:20.460
Then we have 29.

05:21.360 --> 05:22.200
29.

05:23.610 --> 05:27.420
But here we all have noodles.

05:27.420 --> 05:30.060
So here we have noodle.

05:32.400 --> 05:33.360
Newell.

05:33.930 --> 05:35.610
Here we have new.

05:38.610 --> 05:44.970
And also over here we have NULL because we haven't assigned our next pointers yet.

05:45.560 --> 05:46.220
Here.

05:46.400 --> 05:54.840
So now it's time to connect the these three nodes so that it becomes a node chain.

05:54.860 --> 06:01.580
So we will set the next pointers of node one node to object, and we will also set the next pointer

06:01.610 --> 06:02.390
of.

06:03.790 --> 06:05.500
The not to object here.

06:06.310 --> 06:09.640
And we will we will set here the not to object.

06:09.640 --> 06:11.650
So this is the value one.

06:11.650 --> 06:19.690
So node one here, two here and three here and here.

06:21.290 --> 06:25.070
We will set the next pointer of Node one here.

06:25.070 --> 06:30.500
Actually, yes, we will set the next pointer of node one to.

06:32.330 --> 06:34.370
Let's make it cooler here.

06:34.370 --> 06:37.910
So we will set Node one pointer to Node two.

06:38.600 --> 06:42.080
We will set the next pointer of Node two.

06:43.510 --> 06:46.270
Two node one object here.

06:48.250 --> 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

06:57.040 --> 06:57.630
the chain.

06:57.640 --> 06:59.200
So the code here.

07:00.330 --> 07:01.530
Well be like that.

07:01.530 --> 07:03.510
So Node one.

07:03.510 --> 07:06.750
Node one actually, let's add command.

07:09.650 --> 07:12.230
Assign next chapter.

07:12.920 --> 07:15.140
And here the node one.

07:15.170 --> 07:16.220
Next here.

07:16.250 --> 07:18.770
Node one Next is going to be node two here.

07:18.770 --> 07:21.590
As I said, Node one to Node two.

07:23.390 --> 07:31.430
Note two and also note two to note two next to note three.

07:31.670 --> 07:37.010
And as you can see here, we did note three to next to note three here.

07:37.010 --> 07:44.240
So by executing this code, the illustration would be like this, exactly like that.

07:44.330 --> 07:46.460
And the note three is going to be new.

07:46.460 --> 07:48.150
But for now it's like it.

07:48.650 --> 07:51.200
They are also new here for now, not null here.

07:51.200 --> 07:58.790
So because our note next pointer here the next pointer of this note.

07:59.720 --> 08:02.480
Points to here.

08:03.750 --> 08:10.230
Note, actually, if you use a different color, this points to note.

08:20.720 --> 08:21.100
Oops.

08:21.110 --> 08:21.650
Yeah.

08:21.950 --> 08:26.690
So this will point to the node to.

08:29.290 --> 08:32.830
And here this will point to the node.

08:33.700 --> 08:34.390
Three.

08:35.650 --> 08:43.030
And here we actually let create the print function print node function.

08:43.030 --> 08:50.710
And we will with this function, we will print these nodes, uh, printed node chain onto the console

08:50.710 --> 08:51.220
here.

08:51.790 --> 09:01.420
Here we will actually, let's, uh, above that, we will create the print void print node function.

09:01.420 --> 09:03.190
And this will take note here.

09:04.330 --> 09:13.810
As a parameter node and here it will print the initial node until it finds a null for the next pointer

09:13.810 --> 09:15.910
that indicates the end of node chain.

09:15.910 --> 09:22.240
So here, while while node is not equal to null.

09:24.830 --> 09:28.250
Then see out note here.

09:29.180 --> 09:40.460
We also need to implement STD here using namespace std and here C out note value.

09:43.750 --> 09:44.950
And here.

09:46.660 --> 09:47.710
North Valley is going to be.

09:47.740 --> 09:49.780
This is illustrated a little bit.

09:50.380 --> 09:53.230
And here this is our node value.

09:55.920 --> 09:58.050
And after that we will note here.

09:59.050 --> 10:01.840
Node equals node next.

10:06.250 --> 10:15.610
And after that we will see out if this after the looping here, we will see out null.

10:16.880 --> 10:17.300
Yeah.

10:17.720 --> 10:19.070
The noodle here.

10:20.580 --> 10:21.840
And end line.

10:23.270 --> 10:24.590
So here.

10:31.110 --> 10:35.190
We printed the we created the print node function here.

10:35.610 --> 10:39.150
Now, as I said here, we derived our diagram.

10:39.150 --> 10:40.940
The nodes will be like this.

10:40.950 --> 10:48.720
And here after that, after assigning the next and values of our nodes, we will print use the print

10:48.750 --> 10:50.130
node function.

10:50.130 --> 10:53.010
So print node node one here.

10:53.520 --> 10:54.240
Yes.

10:55.700 --> 10:59.870
And let's go to the console here, compile our application.

11:02.420 --> 11:07.280
Here plus plus main main dot CPP.

11:08.800 --> 11:09.460
And here.

11:09.530 --> 11:10.240
Ataxia.

11:13.150 --> 11:18.840
And here, as you can see, we got an in the infinite loop here.

11:18.850 --> 11:20.830
So let's break this.

11:22.080 --> 11:23.360
Cialis.

11:24.120 --> 11:25.930
Let's see what happened here.

11:25.950 --> 11:27.810
So we also need to.

11:28.890 --> 11:31.350
Break our while loop at some.

11:32.490 --> 11:33.270
Condition.

11:34.910 --> 11:39.110
So it's going to be like the C out null end line.

11:39.330 --> 11:45.020
The assign the node new node seven 514 here.

11:48.970 --> 11:49.590
Not.

11:55.530 --> 11:56.420
And after we.

11:56.600 --> 11:57.960
We are returning here.

12:03.980 --> 12:10.100
And here after that, if we just ignore this loop here, go to the top of our code here.

12:10.100 --> 12:12.260
And as you can see here.

12:13.730 --> 12:14.210
Oops.

12:14.340 --> 12:15.110
Uh, here.

12:16.370 --> 12:20.510
Let's actually make it run it again and see what happens here.

12:23.250 --> 12:27.690
So dot x here.

12:29.670 --> 12:32.160
And as you can see here, we have firstly.

12:33.710 --> 12:38.060
The new five year as we did here.

12:38.420 --> 12:40.150
So let's get to this here.

12:40.160 --> 12:47.180
So firstly, we have five, then we have 20 and then we have 29.

12:47.940 --> 12:54.690
After that, it's just a null null zero, which is our while loop isn't breaking here and returned anything.

12:54.690 --> 12:59.910
That's why we have seen infinite numbers here and there is no pointers here.

12:59.910 --> 13:04.620
So that's out with our example here and I'm waiting you in next lecture.
