1 00:00:06,420 --> 00:00:10,410 In the previous lecture, we went over how to set up our linked list. 2 00:00:10,860 --> 00:00:16,500 So now, in order for us to even begin to test our link lists, we need to implement in some methods 3 00:00:16,500 --> 00:00:17,700 on our linked list. 4 00:00:18,000 --> 00:00:22,890 So what we can do is create an implementation block on our list. 5 00:00:23,970 --> 00:00:28,350 And now we can start creating in some new methods. 6 00:00:28,890 --> 00:00:31,140 So we are going to create a new method. 7 00:00:31,140 --> 00:00:37,950 That way we have the ability to even create a new linked list, and it's going to return a self. 8 00:00:38,340 --> 00:00:44,880 And then here we're going to say, We want a list and the head is going to be none. 9 00:00:45,990 --> 00:00:49,460 And that's all we have to do to create a new link list. 10 00:00:49,470 --> 00:00:52,470 So that's something that's really simple to do. 11 00:00:52,800 --> 00:00:58,290 But now let's take it up a notch and let's create the push method. 12 00:00:58,800 --> 00:01:02,520 And push is going to take a self. 13 00:01:03,000 --> 00:01:04,680 And we also need the element. 14 00:01:04,680 --> 00:01:07,560 That way we can give our node some data. 15 00:01:10,170 --> 00:01:17,160 So now we need to say let new node equal a box. 16 00:01:20,400 --> 00:01:26,580 And we want to create a new box and we want to put a node inside of our box. 17 00:01:28,230 --> 00:01:31,010 So we will say element is equal to Elam. 18 00:01:31,500 --> 00:01:36,870 And next is self, dot, head, dot take. 19 00:01:37,800 --> 00:01:45,350 And this is going to take the value out of the option, and it's going to leave a none in its place, 20 00:01:45,360 --> 00:01:54,720 because now that we have pushed in a new element, this is also going to become our head. 21 00:01:54,900 --> 00:01:59,520 So our head is now equal to our new node. 22 00:02:03,480 --> 00:02:11,670 So since we are mutating the list, we actually need to make this a mutable self, because when we push 23 00:02:11,670 --> 00:02:15,750 a new node in, we are updating this list here. 24 00:02:16,200 --> 00:02:20,310 So in order for us to be able to do that, we need to take a mutable self. 25 00:02:23,060 --> 00:02:28,640 And if we implement in a push, then we're going to also implement an app shop, which is going to be 26 00:02:28,640 --> 00:02:29,480 very similar. 27 00:02:29,490 --> 00:02:38,810 So since we are mutating the list, we need to take a mutable reference and when you pop, you are going 28 00:02:38,810 --> 00:02:42,210 to return the value that is being popped. 29 00:02:42,230 --> 00:02:46,880 So since we are returning the value being popped, we need to return an option. 30 00:02:46,880 --> 00:02:58,220 T And so since we want to take the head because Pop returns the last element that was inserted, which 31 00:02:58,370 --> 00:03:03,230 in this case is going to be the head, we can run our self head take again. 32 00:03:03,410 --> 00:03:07,820 But now, since we're taking the head, we need to point. 33 00:03:09,270 --> 00:03:12,650 Our our element that used to point to the head. 34 00:03:12,660 --> 00:03:22,560 We need to make that the new head so we can take a closure pass in the node and say the self dot head 35 00:03:22,650 --> 00:03:24,720 is equal to node next. 36 00:03:26,520 --> 00:03:31,560 And then node dot elm is what we want to return. 37 00:03:32,490 --> 00:03:40,560 So now that we have implemented in these three new methods, we need to have some test cases to make 38 00:03:40,560 --> 00:03:43,110 sure that these are working correctly. 39 00:03:43,110 --> 00:03:50,160 So in the next lecture we will begin creating some test cases in order to evaluate the functionality 40 00:03:50,160 --> 00:03:52,650 of our three new methods.