In the previous lecture, we went over how to set up our linked list.
So now, in order for us to even begin to test our link lists, we need to implement in some methods
on our linked list.
So what we can do is create an implementation block on our list.
And now we can start creating in some new methods.
So we are going to create a new method.
That way we have the ability to even create a new linked list, and it's going to return a self.
And then here we're going to say, We want a list and the head is going to be none.
And that's all we have to do to create a new link list.
So that's something that's really simple to do.
But now let's take it up a notch and let's create the push method.
And push is going to take a self.
And we also need the element.
That way we can give our node some data.
So now we need to say let new node equal a box.
And we want to create a new box and we want to put a node inside of our box.
So we will say element is equal to Elam.
And next is self, dot, head, dot take.
And this is going to take the value out of the option, and it's going to leave a none in its place,
because now that we have pushed in a new element, this is also going to become our head.
So our head is now equal to our new node.
So since we are mutating the list, we actually need to make this a mutable self, because when we push
a new node in, we are updating this list here.
So in order for us to be able to do that, we need to take a mutable self.
And if we implement in a push, then we're going to also implement an app shop, which is going to be
very similar.
So since we are mutating the list, we need to take a mutable reference and when you pop, you are going
to return the value that is being popped.
So since we are returning the value being popped, we need to return an option.
T And so since we want to take the head because Pop returns the last element that was inserted, which
in this case is going to be the head, we can run our self head take again.
But now, since we're taking the head, we need to point.
Our our element that used to point to the head.
We need to make that the new head so we can take a closure pass in the node and say the self dot head
is equal to node next.
And then node dot elm is what we want to return.
So now that we have implemented in these three new methods, we need to have some test cases to make
sure that these are working correctly.
So in the next lecture we will begin creating some test cases in order to evaluate the functionality
of our three new methods.