WEBVTT

00:00.770 --> 00:01.910
In previous lecture.

00:02.090 --> 00:08.480
We get what we expected here so are not chaining is working and we have a new data type named node.

00:09.110 --> 00:11.210
So as you can see here.

00:11.210 --> 00:16.340
So however a problem will occur since we can only store the integer data type to the value property

00:16.340 --> 00:19.040
of our node data type.

00:19.040 --> 00:25.430
So we should we create a new node, that type if we want to deal with another types such as float,

00:25.460 --> 00:27.110
boolean or character.

00:27.380 --> 00:30.500
Fortunately, the answer is no.

00:30.620 --> 00:38.600
If you recall our lecture in the playing with our templates in previous lectures, we can refactor this

00:38.600 --> 00:47.210
code node data type to handle not only the integer data type, but also all various data types available

00:47.210 --> 00:49.250
in C plus plus language.

00:49.250 --> 00:56.360
So here let's actually create our and edit our new node data class which here.

00:58.310 --> 01:01.670
And let's actually delete this here.

01:02.540 --> 01:02.870
Oops.

01:04.020 --> 01:04.500
Here.

01:04.500 --> 01:08.190
Delete this and let's go to.

01:09.040 --> 01:10.870
Are not class here.

01:11.510 --> 01:20.420
So here we have a public and let's actually create the node value and it's going to be the value we

01:20.420 --> 01:23.000
will pass the value to value here.

01:23.000 --> 01:30.110
And we will also, of course, this this is for our template, which we will create now.

01:31.180 --> 01:41.470
Uh, here outside the node class, we will template typename t and here the t value.

01:42.130 --> 01:42.790
Not like this.

01:43.120 --> 01:45.370
Here template.

01:48.800 --> 01:49.460
Aw yeah.

01:50.120 --> 01:52.910
He value here.

01:52.910 --> 02:00.170
Outside of this constructor here value we will pass value as value here and now.

02:00.260 --> 02:03.320
We will pass next here.

02:03.350 --> 02:05.720
Next null here.

02:06.470 --> 02:07.700
So now.

02:09.310 --> 02:10.690
As you can see here.

02:11.520 --> 02:15.500
Well, we optimized here so we can see this code snippet.

02:15.510 --> 02:17.550
We added constructor to the datatype.

02:17.580 --> 02:24.810
The initial actually let's create an initialization of the instance of the class that we will simplify

02:24.810 --> 02:27.150
the class here So we don't need this anymore.

02:27.150 --> 02:28.140
We don't need this anymore.

02:28.140 --> 02:29.850
We will assign it from zero.

02:29.850 --> 02:31.950
And here, as you can see, we got an error here.

02:31.950 --> 02:38.820
We will template the, uh, we have declared the template class here, which in this case I'm going

02:38.820 --> 02:40.590
to just make it a comment.

02:40.590 --> 02:43.080
So we will fix this later.

02:43.080 --> 02:49.440
But first, let's actually create our float nodes here, float node data types here, float here, the

02:49.440 --> 02:56.100
node, it's going to be Node one, the new node here, the here we will actually the implementation

02:56.100 --> 02:58.290
is quite easy as we did in previous lectures.

02:58.290 --> 03:01.320
The node here float.

03:02.840 --> 03:07.100
And in this case, for example, 3.14.

03:08.570 --> 03:10.160
And not here.

03:10.430 --> 03:11.600
Plot again.

03:12.230 --> 03:17.540
The node one or node to the new node.

03:17.750 --> 03:18.920
The float.

03:18.950 --> 03:22.310
And let's make it actually 5 or 6 point.

03:23.130 --> 03:24.120
In 92.

03:25.560 --> 03:26.000
Oops.

03:26.010 --> 03:26.580
Yes.

03:26.580 --> 03:27.630
Let's fix that.

03:27.990 --> 03:28.530
Here.

03:30.340 --> 03:32.160
And not float.

03:32.170 --> 03:33.820
Again, float.

03:33.970 --> 03:40.330
The note three Here we will create a three nodes here the node float.

03:42.390 --> 03:43.980
And in this case, it's going to be.

03:46.040 --> 03:48.260
9.25.

03:49.160 --> 03:56.060
So we can see that now we just need one line instruction to create a single node since it has a constructor.

03:56.060 --> 04:01.330
So the rest of the operation is the same as previous full node in previous lecture.

04:01.340 --> 04:01.820
The.

04:02.270 --> 04:06.380
But in this lecture the full node code for the node template, we will write it here.

04:06.380 --> 04:08.750
So as you can see, we added some code here.

04:08.750 --> 04:14.390
So this is the type name, the compare to previous lecture, the template type name here.

04:14.420 --> 04:16.130
Now we added this.

04:16.900 --> 04:22.140
And after that we will add the type name at the top of our print.

04:22.180 --> 04:26.800
Note here and we will print we will fix our print node here.

04:26.800 --> 04:28.540
And as you can see, we get an error here.

04:28.540 --> 04:33.250
That's because user class template node requires template arguments, argument deduction not allowed

04:33.250 --> 04:34.540
in the function prototype.

04:34.540 --> 04:38.500
So here we will add the template template.

04:38.530 --> 04:45.340
The type name type name will uppercase T and we got an error again because.

04:46.760 --> 04:50.480
The node here needs to get the template here.

04:50.480 --> 04:52.940
And as you can see, our error is fixed here.

04:52.940 --> 05:00.470
So as I said, it will print the initial node until it finds null for the next pointer that indicates

05:00.470 --> 05:01.940
the end of the node chain.

05:01.940 --> 05:04.790
So here this is the same as previous one.

05:04.790 --> 05:06.890
We will change it anything here.

05:06.890 --> 05:10.730
So we fixed our print node here.

05:10.760 --> 05:12.200
So now.

05:14.360 --> 05:20.270
Let's actually create our diagram here and see it on our eyes.

05:20.270 --> 05:21.540
So illustrate it.

05:21.560 --> 05:24.310
So here we have diagram.

05:24.530 --> 05:24.930
Oops.

05:26.640 --> 05:27.840
Here one.

05:29.260 --> 05:29.500
Aw.

05:29.500 --> 05:29.860
Yeah.

05:30.310 --> 05:32.250
So we will have one, two, Yeah.

05:32.260 --> 05:34.210
Four rows.

05:34.240 --> 05:35.140
One.

05:37.180 --> 05:37.900
To.

05:39.340 --> 05:41.890
Three and four.

05:41.930 --> 05:44.380
Here again, This.

05:48.580 --> 05:49.330
Here.

05:52.670 --> 05:54.080
Here and here.

05:54.410 --> 05:57.290
So in the left side, we have our.

05:57.840 --> 05:59.760
The values and pointers.

06:00.000 --> 06:05.580
So in this case, it's going to be let's actually make it the values.

06:13.180 --> 06:13.780
Values.

06:13.780 --> 06:16.210
And here we have pointers.

06:20.140 --> 06:21.460
Pointers.

06:21.940 --> 06:23.380
So here.

06:25.740 --> 06:30.030
Uh, our first node is 3.14.

06:30.060 --> 06:32.730
3.14.

06:32.730 --> 06:35.880
But the pointer is null.

06:37.890 --> 06:41.490
So here we have pointer null.

06:42.750 --> 06:44.610
And here we have.

06:46.120 --> 06:47.530
6.92.

06:47.680 --> 06:51.250
6.92.

06:51.250 --> 06:53.560
And the pointer is also null here.

06:57.690 --> 07:03.060
And here we have 9.25, the nine point.

07:04.510 --> 07:09.040
9.25 and it's also new.

07:15.850 --> 07:16.630
Here.

07:16.720 --> 07:19.210
So now after that.

07:21.850 --> 07:24.400
We will assign the pointers.

07:25.050 --> 07:26.400
So here.

07:28.420 --> 07:30.340
After the initializing our.

07:32.020 --> 07:32.590
Values.

07:32.620 --> 07:35.050
Now let's actually assign our pointers.

07:35.050 --> 07:45.700
So now we're going to node one pointer to node, one pointer to next is not two again, as we did in

07:45.700 --> 07:48.670
previous lecture add node to pointer.

07:49.950 --> 07:56.730
Next two are node tree here, and after that we will print the node.

07:57.680 --> 08:00.460
So in this case, it's it is not.

08:00.470 --> 08:02.150
We will print naught one here for now.

08:02.480 --> 08:03.860
So now.

08:05.690 --> 08:10.460
We are assigning the 3.14 and actually let's change this.

08:10.460 --> 08:20.060
So 3.14 chaining here to Node two here and we are assigning this here.

08:20.060 --> 08:23.950
So now actually we need to delete this null.

08:23.960 --> 08:31.340
Now for the for now this pointers doesn't so for example node one pointer doesn't show null here it

08:31.340 --> 08:37.040
shows the place in the memory of our Node two and node two shows the place on the memory of Node three

08:37.040 --> 08:37.370
here.

08:37.370 --> 08:40.490
So I will illustrate this right now here.

08:42.270 --> 08:49.050
So our node one pointer is chaining to our node two pointer here.

08:49.650 --> 08:53.610
Also our node two pointer here.

08:53.700 --> 09:00.330
Our node two pointer is chaining and showing our here to node three here.

09:00.360 --> 09:03.510
That's why we are printing node one for now.

09:04.080 --> 09:05.370
So now.

09:08.060 --> 09:10.700
Let's actually compile and run our application here.

09:11.330 --> 09:15.170
So close late previous quotes and outputs.

09:15.320 --> 09:22.290
The g plus plus, plus, plus main.cpp and exit here.

09:22.490 --> 09:28.340
And as you can see here, we are seeing firstly the three.

09:29.710 --> 09:31.810
Six and nine.

09:32.110 --> 09:36.160
So we are actually we need to write them in.

09:37.810 --> 09:38.560
Integer.

09:38.560 --> 09:40.690
So we just write them in integer.

09:40.690 --> 09:47.980
But actually, as you can see here, it's just refactoring our outputs and that's how your output is

09:47.980 --> 09:48.340
going to be.

09:48.340 --> 09:51.880
So I will also share this code with you here.

09:51.880 --> 09:53.620
So I'm waiting you in next lecture.
