 What's up guys, my name is Michael and welcome to my YouTube channel today we're going to go over the next problem of insert a node at a specific position in a link list. Basically you're given a link list and then you need to insert your new node of your data at the position of the link list. So here we have 123 we're going to insert a node at position two with data four. So what they did was they create a new node of data four and add position two, which we have zero one two, they're just going to insert it there. Okay. So one two, yeah, zero one two, they insert it here. So it's between the two and the three. Okay. And in this position, we have 16, 13, seven, 16, 13, seven and they're inserting it at insert one at position two. So at position two is zero one two is at the seven. Right. So they inserted the number one before the seven. So it's at 16, 13, one and seven. Yeah. All right. I'm going to explain the code because there's not much to this problem. It's not that difficult actually. So first we need to create our new node. So I did a single link list star new node equal new single link list node at zero. And this is in C++. I create semi data as you go to the point of the data and I set my next pointer to set to null for now. Now I'm going to loop through I'm going to set a current pointer to point to the front of the link list. Okay. And then I'm going to start my position which is starting at zero. I'm going to loop through while current my current my current node is not equal to null pointer right while it's not equal to the end. I'm going to loop through while it's not equal to the end or just in case. And I'm going to go up to the position minus one. And the reason why I'm doing this is because I want to insert it before this position. So if we look at this example one, two, three, I want to insert four at position two, so zero, one, two. I want to insert it before this right zero, one, two. So I actually want to get the previous node before this. So I'm actually going to go to position one, zero, one. Right. To insert this after the previous one. So that's why I use this while loop. So while positions on equal to position minus one, I'm going to go to the next position of my current node and I'm going to increase my position counter. Okay. Now, once I'm at the previous node that I'm going to insert at. So in this case, it's one, two, three, right. Now I'm going to insert it at once I got up to this two, right. I'm going to set twos next pointer to point to my new node four. And I'm going to set my new node four to point to this node three. So if we're going to look at what this looks like, it looks like this. So if I had like one, two, three, one, two, and three. If I set my position at the position I want to insert as two. So I'm going to go to one. So here's zero, one. So basically I'm going to keep going until I reach this node, right. And then I'm going to create my new node of four, which is this four. And what I'm doing is that, excuse me, twos next, twos pointer is right out at three, right. So what I'm going to do is I'm going to actually change this twos next to point to my new node of four. And then I'm going to set fours next to point to twos next, right. So currently twos next points at three, right. So what I'm going to do is I'm going to actually set fours next to point to three for two. Yeah, point to three, which is twos next, and we'll get rid of this. And then we're going to set twos next to point to four. So then I'll insert it between them. So yeah, that's why I do in this code is part of the line of the code. I said currents next current node, which is in our case four. Four is next is going to point to two currents next. So current is at two right now. This is current, right. So the four is next. This next is going to point to twos next, which is three. And that's what this line is doing. And then I said currents next point to new nodes. So currents next is going to point to new node of four. So yeah, and after that, I just returned the head of the link list. And that passed all the test cases. That's basically it just in this problem. Hope you guys enjoy this video. It's not super difficult. Break off, subscribe, I'll check you guys later. Peace.