 Hi, and welcome back. So in this video, we're going to traverse this singly linked list to print all this data out. So here is a diagram again to show you how we're going to do this. Again, this is a singly linked list that is one direction only, meaning that we have to start from the head and then traverse this list all the way to the end until the node is actually nulled and we're done. So we're going to create, introduce a new node. We'll call it current node or current node that will also be pointing to the head node at the start. And then we're going to check the current node if it's at the end or not. If it's not none yet, it's not null yet, then we can keep advancing this current node to the next node and so forth until we reach the end of that node. We use this because we do not want to accidentally delete the head node. If you do that, you're going to lose your entire list. So you want to be extra caution. OK, so let's go back to the IDE and see how this is implemented. So here is our preview example here. Let me clean this a little bit, make it nicer, give us some room. This is the main program. Let's go into the singly linked list and now create our implementation to print this list. So I'll call this one here a function called print in order. And again, because we're printing from the left to right or top, head to tail only. So that's all we need to do. And then after this, we'll do another one, how we can print the first order. Of course, it's not possible. I mean, it's not possible. It'll be a little bit more difficult, but we will show you a different way. So first, again, as usual, we want to check to make sure that our list is not null. We can do that. If it's null, then just return empty string. So normally we'll do something like this called the base case. And say, if self.head is equal to null, non, then you won't print like print, oops, like empty string like that. And then you return. OK, you quit that, right? So that's another way to do it, which is OK. I don't have any problem with that. Maybe it's easier to see that way. And then you can do something like this. And then we can put here turn node is equal to the self.head. And then we're going to check to see if it's a well loop here. So while the current node is not equal to null, we've now reached means that the end yet, then we want to print the current node. In this case would be the current node item, right? And then we want to print that out. We want to advance the current node to the next node. So make sure you do that. If you don't forget to do that, you can run it to an infinite loop. So current node is now pointing to or reassigned to the next node. And that is going to be the current node next. OK, and then keep doing that until the end. And then finally, I want to print that, you know, a list of all the animals next to each other. So I want to put a no blank here. That means no carriage return. OK, so it doesn't have the carriage return. And maybe we'll find a private end here to have the carriage return back. OK, so that's how you could do it. This is one method. And I'll come back and show you how you can actually just remove this altogether. But let's see how to say this works. OK, so say this, go back to our list. And now instead of doing all of these here, we're going to print. Let's remove all of these. We'll keep that prepend just to make sure it's working. We do it before and after. So before we built the list, you want to do a pets list. Oops, all these are still coming in. Not pets, pets. That print an order. OK, this should be empty list. This is the after. And then we'll do a prepend to the front. So the frog is in the front now. And then we print an order again. So you're going to have three lists in here. OK, so let's see if this works. And you know what? Let me clear my console over here a little bit messy. All right, so here we go. The first print was this empty string or empty list. The second print, which is right here after we built the list with three pets, we see that they are printed here. And then we added the frog to the front using the prepend function. And we can see that the order is now correct as is. OK, so that's how you print data to a console. Now let's go back here. Again, I mentioned that this is the base case, right? I mean, because when you check it, it's already checking to see if the current is no or not. Because when we assign the current node to the head, we already verified here. So basically, this is redundant. So you don't really need this. So we can take that out. And then maybe if you want, we could print like this. So print, we're going to start with the bracket like this. And then we'll also make sure that the character is not there. And then we'll also, at the end over here, then we'll print with close that bracket like this. So that the pet will be inside, mess it inside the bracket here. But if it's empty listed, just going to see an empty bracket like you see here. So save it again, run one more time and just run it. And you should see that it looks just like before. Except now, we added the pets inside the brackets here. So it works perfectly fine. Now, how do you print reverse? So because it's a single list, we have only one direction. It's a little bit challenging if you were to do it and using loops and things like that. But I'll show you that you can actually do this very simple using a recursion. So let's go here and do a recursive call. So we have print, I should say print a reverse. And then we're going to do a recursion call. So internally, we're going to have another function call when we recurse. And we're passing this recursion the actual node itself. So you put here node. What do we call it? It's an object, right? So that we would check the node before we do this down here. We're going to call the function. So we put here. So you could do like, we can check. Well, let's print first. I'm going to copy this one here over here. I need that to the front. And then at the end, I need this to the end. I'm making a shortcut here. So in between is why do the recursive call, right? So I'll do a recursive. I'm going to pass to this function the head node. I'll start from the head node. And once you go to the head node, then it's going to recursive down here. And it keeps going until the end of that list. So we go to the recursion call. We pass in the head node. And OK, so I want to check if the current node is null. If it is, then we just return it. Nothing's returned. So this is already the base case for this up here. We do the base case here. Same thing. We pass the head to this node function. We check if it's none already. And we exit our done. If it's not none, then we're going to do a recursive call here. Pass in the next node will be the node.next. And then we keep doing that. And then after we're done, we're going to recurs everything back. Because every time you call the recursive function, it passes to the stack. So the stack, it's like the regular stack. First and last out, right? So that when we finish recursion, we wish the end is going to return, recurs back. And then we do the printing right down here. So the order isn't born here. So here, I'm going to put the current. I'm going to copy this right here. And instead of a current node, we just call it node.item. If you put it at the recursive call, then it prints a reverse. If you put it before the recursive call, you print the order. So this actually, its behavior is quite interesting. So let's say that and go back to our program. And I'm going to print right down here at the end down here, OK, just the last one here. We'll do a reverse print. Do a print to reverse. And then if it's correct, you should see the reverse at the very last list here in reverse order. So here we go. This is the order in order and the reverse order as you see here using recursion. OK, so I'll stop here. And in the next video, I'm going to show you how we can insert data in between these nodes.