 What's up guys, my name is Michael and welcome to my YouTube channel today We are going to go over how to delete a node at a certain position in a link list so First of all to delete a note at a certain position at the link list Basically, let's say in the input we have 26 297459 and we want to delete the note at position three. So at position three it would be 0123 so the 19 is gone. So as you can see in here you have 26 2 and Then the 19 is gone. It becomes 7459. Okay. All right, so how would you do this? simplest ways just to go to right before the the node that you want to delete so That we want to leave 19 we go to the 2 and then we just set the next Pointer of two to point two seven right the one after 19 So we just point twos next is gonna now point a seven and then the 19 is now gone So, yeah, so let's actually do that. So how do you do this? Let's actually strict create. We're gonna create a current node And we're gonna point it to the head of it have the list and then what I'm gonna do is I'm going to Start my position zero and I'm going to do while current is not equal to the end and My position is not equal to my end position minus one Okay, let's actually call this current position So my while my current position is not equal to position minus one. This is then I'm gonna do a Current equals a current next so I keep going to the next node And then I increment my position and what this does is this is going to make me go to the The node right before the one that we're moving. So if I'm removing 19 right at position three zero one two three I'm gonna stop at two and then set twos next to point to 19s next. So, yeah to do that Once we're here, we're just gonna set currents next What do you close currents next? next and Ideally that should remove it and now we're just gonna return the head of the list. Yep. Okay. We're missing a test case We seg fault it Let's see Okay, we have to check if current is not equal to no pointer Right cuz in case if we hit the end of the list Right. Okay. We're still seg faulting. What are we seg faulting? Wrong answer. Well, if this is the case If current's next current is I equal to no pointer then we need well We also have to check if current's next next not equal to no Then we could do this. So I'll put this here and it should work and now Okay, we're still fail. I don't know what we're failing Can I just unlock this? I'm gonna lock it. What am I deleting? Hold up Let's run it. What are we deleting? What's the expected output your standard output is 11 12 8 18 16 5 18 Oh, we're deleting our position zero Current's next gonna concurrence next next. Oh, okay. So if the current Position is equal to zero What I'm gonna do is I'm just gonna return lists next and this is a hacky way to do it But it's going to get rid of the Yeah Basically what I'm doing is um I'm not really I'm just gonna return the next node. So it's not gonna do anything. Um, you tell me I could just set lists Equal to list next and then return list. That's how you do it Let's submit this code and that's pretty much the gist of it I hope you guys know this video very come subscribe. I'll check you guys later peace