OK.
So previously, we looked at the singly linked list being templated, and now we are actually going
to change it to a link list.
So this is actually going to be a pretty short video.
There is not a lot we have to do actually to change this from single English to double link list.
But as you see, I have already added my or changed my preprocessor directives here to accommodate for
us having a link list and just renamed it basically.
So you can do that as well.
I did it here in the L.A. header and the list header as well.
So let's go ahead and get started, so if you remember pretty much all we have to do.
Yeah.
Basically, the difference between a single rolling list and the mailing list is just that previous
pointer.
So each node will not only have a pointer to the next node, but it'll also have a pointer to the previous
node.
So to accommodate that, we're pretty much just going to copy what we have here for our next.
And just do that for previous and I am going to just call that.
So I'm doing a templated L node pointer here, and I'm I call that underscore preve.
And so I'm also going to make some functions here.
This is going to be returned and it's included L.A. and we're just going to call that preview and then
we'll do our setter one here.
So this will also like that and I'll just call that you as well.
OK, and that's all we have to do in here, actually.
So let's head over to the implementation file to add these.
So I am going to put it right here.
So this first function
and this is just going to return our crew underscore preve data, remember?
I'm going to go down here to end this next one.
And this is our deployed function, and I call this preve, and it's going to get past a typically known
point or for setting the previous note.
And I will just say preve underscore preve equals to past preve.
OK, so that was pretty simple.
We just added that in there.
We also want to come up here, though, and set initialize our three pointer to null pointer the constructor
there.
And that is going to be it, actually, I believe, for our nodes, a node class.
I don't think we need to do anything in the header of the link list.
So we're just going to head straight to the implementation.
What we're going to be changing here.
Is this part and that part?
So if we have size zero and we're just adding a new node, the previous pointer that preve pointer and
the next pointer are both just going to be no pointer, so we don't have to worry about setting those.
But here, when the size is one, we're setting our next pointer to new node.
But we also now need that new node to point back to head somewhere, do new node arrow preve and then
set it to head because head's pointing to new node and new nodes going back to head.
You see, we set our tail here, so we're all good with that already.
Down here and do the same thing pretty much, but it's going to be with carrier, so currents next is
equal to null pointer in this condition.
And then right here we set next equal to our new node.
So it's going to be the final node in the list.
It's going to be the tail, which is what we see right here.
But in between setting the tail and setting currents next, we're going to do the same thing where we
go.
New nodes, previous pointer points to her.
And so now we're pointing back each time when we add a new node.
And all the only other thing we really got to do is to prove that our link list is working.
I'm going to go ahead and make this print function go forwards and backwards, so head to tail and tail
to head.
And to do that, I'm just going to actually declare another point I and call it backwards.
Kerr actually said an eagle, a tail because we're starting out with tail.
I'm going to go ahead and put OCR statement here and say for words.
So we know when we're going forwards and then I'm going to say just do a new line and then say backwards
here.
OK, and we're pretty much just going to copy this
paste array here, but we're actually going to say backwards, Kerr.
So while backwards, Kerr is not equal to null pointer, we want to print out backwards curve data and
we have put our arrows the same.
And then we're going to say backwards cur equals backwards curve and we're going to use the three pointers
to traverse this list in reverse.
And I'm also just going to do a little.
Let's just put a little like new line here.
OK, so now we're putting our forwards and backwards, we actually don't need to modify anything in
our main because we're still going to do the same thing using our print function for both lists.
Our input files still has this one two three four five six seven a 3G in it, but it's going to print
out a forwards version and a backwards version using the next pointer for the first in the pre four
pointer for the second version there, so we can confirm that our link list implementation is actually
working.
So let's go ahead and run this.
Hopefully it runs well.
We don't run the errors.
But while this possibility?
OK, looking pretty good.
All right, so there we have our forwards one through seven and then we have spring out backwards and
then it goes in reverse and everything looks pretty good.
Both of our types of lists.
OK, so I know that was a short video.
We're actually going to get into a couple of problems after this and look into insertion and also maybe
just some little.
Kind of test sound like interviewee problems where you have to do a specific thing with the delay list
now that we have two different types, so maybe some coding exercises and then we'll put some video
solutions for you, but hopefully this was clear enough.
Really not modifying very much to make it a link list and still have the template option.
So, all right, I will see you in the next lecture then.