 Hi and welcome back in this video we're going to implement the prepanded function where we're going to add a new node to the front of the list. Now in the previous video we added the appended function where we add data to the end of the list so make sure you watch the video if you have to but let's go back to the diagram for a second here so this time we're going to push a new item to the front of the list okay so when we do this if the list is empty of course they're both to be the head of the tail we're pointing to the node and we're done otherwise if there's at least one node in the front so we want to make sure that the new nodes point the next node to the head first okay if you don't do it correctly you're going to lose the data so you got to point the new nodes next node to the current head node and then we just have to basically change the head pointing to the new node as the new head that's all you have to do very simple implementation so let's go back and do this operation all right so here we're going to do a new function down here we'll call it prepand and self also take the new item come in just like above we're going to create a new node and this is the node item and then again we're going to check to see if that head is null or not if it is then you know the both are actually the head already so self that head is equal to the new node you can see some you know code repetition here you can see that i'm adding this to the new to the head this to the head right so you could write another function just to say add to head add to tail right so you don't do to do this every time but that's okay otherwise if there's only one at least one node then we're going to do the following right very simple again we want to make sure that we do the new node that next pointer points to the current node is in this case it'll be the head node right we want to point that first okay if you do it opposite you'll lose that you'll lose the entire list okay so self that head is not pointing to the new node okay by swapping these two order you're gonna lose an entire list so be really careful when you do this and then again after that then we want to go back and change the size to a plus one okay as you can see very simple to do that and add to the list so now let's go back to the main program over here and add a new list so we're gonna have this as in the list we're going to go ahead and add a new one down here i'll call it down here so we can see what it looks like before and after okay so let's go ahead and add um oh what should we add over here um let's see i put here uh pets list dot prepend right prepend we're gonna prepend a new pet let me grab another emoji here let's add i don't know a froggy okay i put a frog right in here okay so that means this frog is gonna be the one in the front of the dog okay if it's correct right so we can confirm that by calling this function like this code again i'll put it right below here and so the first item should be the frog and you know what maybe i should do this i'll make it down i know it's not um nice yet but what do later when we do a feature video we're gonna do the intro Rosso and print data the data together so let me just update this really quickly so we can see what's going on inside here i basically want to put them you know and side by side okay so let's see this the before and after and see if this works okay so you can see that um we actually lost something here did i lose something oh no no again i didn't print the fourth item right so we see that the the previous list has three dogs three pets and then we prepend the frog to the front of the list so you can see that the first item let me do this okay it's easier to see this way sorry guys so the first item is actually the head if you add another one to the fourth list you can see how this is a um you know a precursor to the traversal and it's that item you have the four four item now and you can also print the size maybe to put here um you know uh pets list that size okay you get the size and we see that it should be three there and then here should be four okay so here we go let's run again and we see that the pet side is three now we have printed the frog to that list now we have four so again the implementation looks very similar to detail in the head only thing you have to watch out for is the order of these down here okay again if you do it incorrectly you're going to lose the data if i swap these two also i want to lose the data so be careful when you do this i mean just follow the arrow the you know the the nodes what should happen first you have to take care of the next node really really carefully okay so that is it so in the next video we're going to learn how to traverse the the list so we can print them out you don't have to do these manual work here okay so see you guys in the next video