In previous lecture.
We get what we expected here so are not chaining is working and we have a new data type named node.
So as you can see here.
So however a problem will occur since we can only store the integer data type to the value property
of our node data type.
So we should we create a new node, that type if we want to deal with another types such as float,
boolean or character.
Fortunately, the answer is no.
If you recall our lecture in the playing with our templates in previous lectures, we can refactor this
code node data type to handle not only the integer data type, but also all various data types available
in C plus plus language.
So here let's actually create our and edit our new node data class which here.
And let's actually delete this here.
Oops.
Here.
Delete this and let's go to.
Are not class here.
So here we have a public and let's actually create the node value and it's going to be the value we
will pass the value to value here.
And we will also, of course, this this is for our template, which we will create now.
Uh, here outside the node class, we will template typename t and here the t value.
Not like this.
Here template.
Aw yeah.
He value here.
Outside of this constructor here value we will pass value as value here and now.
We will pass next here.
Next null here.
So now.
As you can see here.
Well, we optimized here so we can see this code snippet.
We added constructor to the datatype.
The initial actually let's create an initialization of the instance of the class that we will simplify
the class here So we don't need this anymore.
We don't need this anymore.
We will assign it from zero.
And here, as you can see, we got an error here.
We will template the, uh, we have declared the template class here, which in this case I'm going
to just make it a comment.
So we will fix this later.
But first, let's actually create our float nodes here, float node data types here, float here, the
node, it's going to be Node one, the new node here, the here we will actually the implementation
is quite easy as we did in previous lectures.
The node here float.
And in this case, for example, 3.14.
And not here.
Plot again.
The node one or node to the new node.
The float.
And let's make it actually 5 or 6 point.
In 92.
Oops.
Yes.
Let's fix that.
Here.
And not float.
Again, float.
The note three Here we will create a three nodes here the node float.
And in this case, it's going to be.
9.25.
So we can see that now we just need one line instruction to create a single node since it has a constructor.
So the rest of the operation is the same as previous full node in previous lecture.
The.
But in this lecture the full node code for the node template, we will write it here.
So as you can see, we added some code here.
So this is the type name, the compare to previous lecture, the template type name here.
Now we added this.
And after that we will add the type name at the top of our print.
Note here and we will print we will fix our print node here.
And as you can see, we get an error here.
That's because user class template node requires template arguments, argument deduction not allowed
in the function prototype.
So here we will add the template template.
The type name type name will uppercase T and we got an error again because.
The node here needs to get the template here.
And as you can see, our error is fixed here.
So as I said, it will print the initial node until it finds null for the next pointer that indicates
the end of the node chain.
So here this is the same as previous one.
We will change it anything here.
So we fixed our print node here.
So now.
Let's actually create our diagram here and see it on our eyes.
So illustrate it.
So here we have diagram.
Oops.
Here one.
Aw.
Yeah.
So we will have one, two, Yeah.
Four rows.
One.
To.
Three and four.
Here again, This.
Here.
Here and here.
So in the left side, we have our.
The values and pointers.
So in this case, it's going to be let's actually make it the values.
Values.
And here we have pointers.
Pointers.
So here.
Uh, our first node is 3.14.
3.14.
But the pointer is null.
So here we have pointer null.
And here we have.
6.92.
And the pointer is also null here.
And here we have 9.25, the nine point.
9.25 and it's also new.
Here.
So now after that.
We will assign the pointers.
So here.
After the initializing our.
Values.
Now let's actually assign our pointers.
So now we're going to node one pointer to node, one pointer to next is not two again, as we did in
previous lecture add node to pointer.
Next two are node tree here, and after that we will print the node.
So in this case, it's it is not.
We will print naught one here for now.
So now.
We are assigning the 3.14 and actually let's change this.
So 3.14 chaining here to Node two here and we are assigning this here.
So now actually we need to delete this null.
Now for the for now this pointers doesn't so for example node one pointer doesn't show null here it
shows the place in the memory of our Node two and node two shows the place on the memory of Node three
here.
So I will illustrate this right now here.
So our node one pointer is chaining to our node two pointer here.
Also our node two pointer here.
Our node two pointer is chaining and showing our here to node three here.
That's why we are printing node one for now.
So now.
Let's actually compile and run our application here.
So close late previous quotes and outputs.
The g plus plus, plus, plus main.cpp and exit here.
And as you can see here, we are seeing firstly the three.
Six and nine.
So we are actually we need to write them in.
Integer.
So we just write them in integer.
But actually, as you can see here, it's just refactoring our outputs and that's how your output is
going to be.
So I will also share this code with you here.
So I'm waiting you in next lecture.