 Hey everybody, so this video we'll talk about appending to our linked list and rather than diving into the code, we'll just work on the whiteboard this time and Kind of plan out what our pseudo code is going to look like, okay? So appending to the list Let's follow our mantra on this one Okay, and let's plan what we're going to do and then let's also bring it down in terms of input Compute and then output steps one two and three first get your inputs second to do your computation third produce your output Or if there is any right? So That those three steps don't just apply to like reading files and doing something and spitting out something to the screen it could also apply to methods or function calls because Methods and function calls have input that's its parameters, right? And then they compute and then maybe maybe they return something but not always and that's okay It's still going to help us to think of things in those terms So let's plan our list dot append around this So appending to a linked list is conceptually the same as appending to any other list You are adding it to the end. You're putting an item at the end of the list Okay, now when we we're going to write our code and our code is going to look like List dot append when it gets called and it'll look kind of similar to the add method but with you know a key difference so What do we do? What are you going to do the first step is you're going to You know get your data get your input Well, what is your input your input is going to be the function the method parameter the data item so you need to make first thing we probably need to do then is Make a node For the item For the data right first step make a note for the data Now I want to get it into the list in the right spot Now your linked list class it again. It only knows three things the head the tail And the length of its list of a number of items inside. All right So what are the scenarios again? You're going to it's going to be useful to think of each one of these methods in terms of like special scenarios. Well one scenario is The list Has It has some items so It's length is greater than zero Okay, so it's got some items in it. How are you going to append to a list that already has items in it? well You know you you've already got a list. I'm not going to draw a whole bunch of stuff here and any great detail But you've already got a list With some stuff in it right in the head Of the list is up here in the tail It's down here. Okay Well, where do you want to append? You append at the end of the list Well, you have a reference to the end of the list. It is called the tail right? so How do you append? You want to put Right, you want to put the new guy down here Right at the very end right which means what how do we get the new guy there? You got to put the current tail in the list tell them To point to the new guy. I'll call this guy new right here. Okay, so you got to take the current tail point it to the new guy So I'll say point Current tails Next right the node at the tail has a data and the next to the new node and then and then what Then you need to change the tail doesn't belong to the second to last guy it belongs to The one you just inserted So you got to update the tail To point To new right And when I say point to update it to point to I'm just saying reassign the valid that variable to get the new node right so trail dot next is new and Tail gets new right this will make the link Okay, so That would take care of that scenario and then the next scenario will be well list has a Length equal equal to zero Okay, if you are you are appending to an empty list Well, what happens when you append to an empty list? You know both the head and The tail Need to point to the new item Okay, just like that. Just like it was for add same thing. Okay Cool, what else do we have to do update? The size can't remember to do forget to do that if we're adding and removing things one of the last things You need to do is update the size of the list, okay? All right, I Think that gets us there We've got kind of our input step We've got our computations and then our what's our output. Are we returning anything? No Whenever you append to a list you do not return anything list dot append does not return anything So we're done Okay, so here's kind of the pseudo steps the steps of our algorithm looks kind of similar to add I'm going to leave it to you to implement it and next time we're going to talk about Something a little more challenging which is searching the list That's going to be our first case where we have to traverse or walk the list. All right. See you then