Hello, my name is Stephanie.
Welcome to another lecture of our course.
In this lecture of our course, you will learn about the nodes here.
The Nord is a basic building of many data structures which we will learn in this course.
So Node has two functions, Node has two functions.
The first function is that.
It.
It holds a piece of data.
The first function holds a piece of data also known as value.
The second function is that the connectivity between another node and itself using an object reference
operator.
Another reference pointer, also known as the next year.
The.
Next pointer.
Peter So based on this explanation, we can create a node datatype in C plus plus here.
So firstly, let's actually make this like that here.
Yes.
Oops.
Yeah.
Make it here and let's create a node here in real life.
In Cplusplus here.
So firstly.
We first need to create a class node.
Here the class node and we will define oops.
Yeah.
Class node.
Here we will.
Inside this node we will create a two public variables.
The first is integer value and next is a node pointer, which is the next pointer.
As you can see here, the next pointer.
So node pointer and next.
So we will also use this diagram here.
We will here.
Let's actually create the diagram.
This is our diagram, which in left side we would have the value value.
In the right side we will have next.
Here.
So now let's create three single nodes using the new the new node data type.
So the nodes will contain values of five, ten and 25 or 5, 10 or 29, for example.
So here we will create a node.
So, for example, in this case, it's going to be node one.
Node one.
The new Node.
New node.
Here we will also create the actual node one.
Node one.
Here assign it to value.
The first value in node one is going to be.
As I said.
Yeah.
Five and let's create a Node two here.
Node Node two.
New node here.
And Node two value is going to be.
Value.
It's going to be, as I said.
Yeah.
20 for example.
And note three here.
Let's create note three here.
Note a note three.
New.
Not here.
And the node three value.
Node three value is going to be 29.
So now that since we don't initialize the next pointer for all nodes, it will be automatically filled
with the null pointer.
So all of these here actually let's make it like that that you would understand.
Everyone will understand here that here.
We will delete this.
We previously created.
Here.
Now, we will make a diagram for the nodes.
So here.
Here.
So now we will drive some items to it.
So we have three nodes.
We will have three rows here and two columns.
Here.
So we will also need to create a rose here.
One.
Two and three for now.
Three is okay.
And here the in the left side of our node.
We have five here.
Five.
And then we have the 20.
Oops 20.
Then we have 29.
29.
But here we all have noodles.
So here we have noodle.
Newell.
Here we have new.
And also over here we have NULL because we haven't assigned our next pointers yet.
Here.
So now it's time to connect the these three nodes so that it becomes a node chain.
So we will set the next pointers of node one node to object, and we will also set the next pointer
of.
The not to object here.
And we will we will set here the not to object.
So this is the value one.
So node one here, two here and three here and here.
We will set the next pointer of Node one here.
Actually, yes, we will set the next pointer of node one to.
Let's make it cooler here.
So we will set Node one pointer to Node two.
We will set the next pointer of Node two.
Two node one object here.
And we will keep the next pointer of Node three remain the null here to indicate that it's the end of
the chain.
So the code here.
Well be like that.
So Node one.
Node one actually, let's add command.
Assign next chapter.
And here the node one.
Next here.
Node one Next is going to be node two here.
As I said, Node one to Node two.
Note two and also note two to note two next to note three.
And as you can see here, we did note three to next to note three here.
So by executing this code, the illustration would be like this, exactly like that.
And the note three is going to be new.
But for now it's like it.
They are also new here for now, not null here.
So because our note next pointer here the next pointer of this note.
Points to here.
Note, actually, if you use a different color, this points to note.
Oops.
Yeah.
So this will point to the node to.
And here this will point to the node.
Three.
And here we actually let create the print function print node function.
And we will with this function, we will print these nodes, uh, printed node chain onto the console
here.
Here we will actually, let's, uh, above that, we will create the print void print node function.
And this will take note here.
As a parameter node and here it will print the initial node until it finds a null for the next pointer
that indicates the end of node chain.
So here, while while node is not equal to null.
Then see out note here.
We also need to implement STD here using namespace std and here C out note value.
And here.
North Valley is going to be.
This is illustrated a little bit.
And here this is our node value.
And after that we will note here.
Node equals node next.
And after that we will see out if this after the looping here, we will see out null.
Yeah.
The noodle here.
And end line.
So here.
We printed the we created the print node function here.
Now, as I said here, we derived our diagram.
The nodes will be like this.
And here after that, after assigning the next and values of our nodes, we will print use the print
node function.
So print node node one here.
Yes.
And let's go to the console here, compile our application.
Here plus plus main main dot CPP.
And here.
Ataxia.
And here, as you can see, we got an in the infinite loop here.
So let's break this.
Cialis.
Let's see what happened here.
So we also need to.
Break our while loop at some.
Condition.
So it's going to be like the C out null end line.
The assign the node new node seven 514 here.
Not.
And after we.
We are returning here.
And here after that, if we just ignore this loop here, go to the top of our code here.
And as you can see here.
Oops.
Uh, here.
Let's actually make it run it again and see what happens here.
So dot x here.
And as you can see here, we have firstly.
The new five year as we did here.
So let's get to this here.
So firstly, we have five, then we have 20 and then we have 29.
After that, it's just a null null zero, which is our while loop isn't breaking here and returned anything.
That's why we have seen infinite numbers here and there is no pointers here.
So that's out with our example here and I'm waiting you in next lecture.