 Hello friends, I am Sanjay Mukta. I welcome you on Sanjay Mukta Tech School. In this video, I am going to explain how you can implement these three methods with the help of steel address. So first is delete first, second is delete last and third is delete after. And we are going to apply these delete operations on senior leaders. So if you want to watch how we can implement their algorithms, so you can find link of that playlist in the description of this video. But in this video, I will be telling you how you can write functions. Those are implemented in steel address related to these three operations. So first time we delete first. So let's focus on this single address. Let's say this link is already created and we want to delete first node. So address of first node, base address is one on one which is stored in start pointer. Then this node link part is ready address of second node. Second node link part is ready address of third node. So this way we create links. And if you want to know how we can create links, so that video is also available in that playlist. So all the links are available in the description of this video. So you can go and watch. So now let's implement delete first. So this is written time. Then the function is the first and it will be receiving a pointer in start. So through main function, this day first function will be called and main function will be passing address of first node. And that address is stored in the start pointer. So this start pointer will be passed to main function and that will be received into this pointer. Now I'm going to delete one more pointer, start one more pointer, delete. Now I'm going to check if start double equals to none. So why I'm checking this because if linkless is not having any particular node, so it means your linkless is empty. So that needs to be checked. So if start equals to null, so in that case we can print underflow. It means linkless is not having any particular node. So you can print the message as per your requirement. So underflow means that we don't have anything to delete and return. So return will terminate execution of this method of function. So if start equals to null, it means there is no more availability that we cannot delete. If this condition is false, like this is a scenario, linkless is having three nodes and we need to delete this particular node first node. So what we need to do, we need to remove this from this linkless. So right now this first node address is having a connection to start. If we try to delete this node, it means this will become first node. So this node base address that is 2001 should be available into start. But right now it is available into this position. So this is basically link of first node and first node address is having a connection to start. So what we can do, p equals to start. So p is a pointer which will have address of first node that is 1001. Now I can find start equals to link. So start is basically off time structure. So whenever we access member of structure to pointer, then we need to use this error notation. So this you can create by iPhone and click inside. So start is having 1001, its link is having 2001. So that will go into start. So new value of start will be 2001. So here you can see 2001, it means start is now pointing to this node. So this became first node, this became second node and this is not part of this linkless, its address is available into this p pointer. Now if you want to see this memory so that any other program can utilize this memory, so for that you can write pp and you can return start because in this function we modified the address which is stored in the start. So we need to return this so that it can be received by the main function. And now I am going to do it. So this way I implemented first logic which is based on delete first. So we deleted first node from the linkless So I hope you understood this. Now I am going to explain delete class logic. So first I am going to explain how we can write the function for delete class. So delete class means we need to delete this node from the linkless. So there can be two scenarios. First like we are going to delete the node which is the only node in the linkless. Like you are going to perform delete class operation but your linkless is only one node. And second scenario is your linkless is having more than one node and you need to practice each and every node and you need to move to last position and last node will be deleted. So here we covered both the scenarios. So now I am going to write a method. So return type will be start move pointer. Then delete last name of function then it will receive address of first node into this start function. So this function will also be called as main function. Main function will be passing base address of the first node. So in main function we also have start pointer. So that will be passing the address of first node and that is received into this pointer. Now I am going to create two more pointers. So first is preview here and second one is preview here. Now if start is null. So this is the case. Your link is already empty. It is not having any particular. So this condition you also check in case of delete path. So here you can print attitude and return. So return will terminate this execution of this function. So that's why I mentioned this. So this is the scenario where linkless is empty. So we already checked it. Now if linkless is not empty it means now we need to check whether we have only one node in the linkless or we have more than one node in the linkless. So for example, first I am assigning start into PTR now. I am applying if condition to if I am checking PTR link double equals to null. So this is the case which says linkless is having only one node. So for example I am modifying this linkless. So let's say this is start and this is first node which whose base address is 1001 it is stored here 10 and null. So this is our linkless which is having only one node and we are going to delete this one. So start is assigned into PTR. So PTR will be pointing to this node. Now we are checking PTR link. So PTR is 1001. Its link is null. So this condition is true. It means the node which we are going to delete is the only node in the linkless. It means now we can assign null into start because if we delete this node it means now linkless will not be having any particular node. So it's start will be equals to null and after completion of this code we are going to return the start so that actual linkless that is available in the link function will be online. If this condition is false it means this is the standard. Linkless is having more than one node. So if it is false it means PTR link is not null. So I am erasing this from here. This we already covered. Now we are going to copy this. So linkless is having few nodes. PTR is pointing to the first node. Now we need to iterate a loop so that we can do the last node. So here I am checking why PTR link not equals to null. So if PTR link is not equals to null then we need to move to next node. So right now PTR is here. In second rotation PTR will move to here then PTR will be here and then PTR link is null so it will stop. Now what we need to do? We need to assign null at this location because we are going to delete this node. So we need one more pointer that is pre PTR. So when PTR will be pointing to the last node then in that case pre PTR will be pointing to this node. So right now PTR is pointing to the last node. Its link is not equal to null so PTR will be pointing to second node. So when PTR will be pointing to second node so pre PTR should point to this node. So how you can achieve this? So you can assign PTR into pre PTR. So PTR is 1001. Let's say this is pre PTR. So now PTR is assigning its value to pre PTR. So it will be having 1001 and PTR equals to PTR link. So this will be the case. So PTR link so PTR is 1001 its link is 2001. So now here 2001 will be connected and you can close this. Now PTR is pointing to 2001 and pre PTR is pointing to 1001. So pre PTR is on first node PTR is on second node. Now check this condition PTR link so PTR is 2001 its link is 3001 its not equal to null. So PTR will assign its value to pre PTR. So it will become 2001 and PTR link it is 3001 that will come here. So right now PTR is pointing to this and pre PTR is pointing to this. So PTR link so PTR is 3001 so it means this node will be connected. So right now we have both the pointers the node which we are going to be is pointed by PTR and its previous node is pointed by pre PTR. So now what we can do? We can simply assign null to this location and this location we can access to pre PTR. So after completion of this loop you can add pre PTR link equals to null. So it means here null will be assigned. So if this node is having null it means this node is automatically deleted from the link list. And now if you want to delete that node actually so after this else so if else both are completed so after that we can assign pre PTR. So PTR will be pointing to a particular node. So in that case if this condition is true in that case PTR will be pointing to the only node that is the physical connection. And in else case PTR will be pointing to the last node that is the physical connection. So in both the cases we are going to pre PTR and at last we can assign pre PTR start. So if this is the case then start will be changing so we need to return this and if this is the case then start is not changing then also we need to return this. Or you can write this PTR also and this is completed so I am marking it as PTR. So this way I explained you second method practice delete class. So in delete class we have two knowledge. First one is covering when link list is having only one node and second is covering when link list is having more than one node. So this way this is the key function or you can say delete last I was of this implementation by a key. So I hope you understood how this code is working and now you can implement this code into your compiler. But don't forget delete to all this delete class function to main function. You might be thinking like can you explain or can you implement this code on ID or any compiler so that we can do how we can call this method in main function or other methods. So for that purpose you can go to description of this video. You will find link of there is like DSA or implementation using ID with help of key language. So if you open that playlist you will find a video related to code implementation of link list. So where I have implemented insertion, deletion, travers, and all the codes will be available in the program. So you can watch and you can view like how we can manage the code of single link list to gather in the same program. So now we cover delete class. So next is delete after. So in case of delete after we are going to delete a function from the pretty of the link. So after explaining this now I am going to case this so that we can discuss delete after. So now I am going to explain how you can connect the code for delete after operation. So in case of delete after you need to specify which node you are going to delete. So let's say I am passing position as 2. So it means I am going to delete the node which is on third location or third position. So delete after. So I am saying position is 2 you need to delete the node which is after second position. So second position is this so we are going to delete this. So this way the code will be working. And again if you want to watch the algorithm related to delete after. So that link is available in the description. So you can go to and watch that. So now in this case we are going to delete after because we are not going to change the start. And we already know there are a lot of nodes available in this. And we are going to delete any middle node. So why delete after then construct node pointer start and delete the position right. Now this start will be having address of first node that will be provided by main function. And position will be having the value after which node will be deleted. So if position is 2 it means we are going to delete third node. If position is 10 it means we need to delete the 11 node right. So now I am creating one pointer that is PTR right. Then in these are I. Now I am deleting the node. So I is one and PTR equals to start. So these two are initialization statements. Then condition is I as a position. So if I is as a position then this loop will be otherwise it will become. Then I plus plus comma PTR equals to PTR link. So I will be limited by one and PTR will be pointing to next location or next node. Now if PTR is null. So let's say position is 4 and we are moving from one node to another. So there will be a scenario when PTR will be equals to null. It means we need to print and access. So the position you specified that is not applicable in which we cannot define the region of it. Otherwise this loop will execute properly and it will be calculated naturally. And your PTR will be pointing to that location after which or you can say if PTR is pointing to second node. So it means we are going to delete the third node right. So let's integrate this to position values to I is one PTR will be pointing to start. So let's say PTR it will be added 1001. Now check the condition I as a position. So it is true because I is one and position is two. Then PTR double equal to null so it is false. Then I will be incremented to I is two and PTR will be PTR n. So PTR is 1001. So PTR will be pointing to 2001. So right now I is two position is two so this two will be calculated right. So in our case PTR is pointing to second node and we are going to delete this third node. So it's length is 1003,000. So in previous example in Delhi class I mentioned 1001. Assigning 3001 which is the address of this node and it will be stored here. So now PTR is on second node and we are going to delete third node. Again let's say you integrated this loop and PTR was not equals to null. This loop got complicated and in case your PTR is pointing to last one. For example PTR is pointing to last one. So you entered position as three right. So PTR was not equals to null and PTR is pointing to this location. But after this node any other node is not available. It means delete after cannot apply it because you are on PTR, you are on third node. PTR is on third node but after that no node is available. So in that case you can check this condition. If PTR length is null. So you entered by mistake last position. You entered by mistake last position or position of last node. So it means after that node no node is available. It means delete after cannot be applied. So here because I delete that. So you can frame a particular message for here. No node is there for delete and return. So this you also need to take care of. But in our case PTR is pointing to this and PTR length is not null. So this will be false because PTR length is 3000. Now what we need to do? We need to assign this null here. So that this node will be deleted. So let's say we have one more node. So it is 3000. We have one more node that is 4140 and null. And its address is 4000 length. So now we are on second position. So what we need to do? This node will be deleted. So this node's address should be here. It means second node length part will be having address of fourth node. And only this node will be deleted. But this node 3001 is having address of fourth node. So from here we need to assign this location to here. So how we can do that? So you need to write PTR start. So PTR is pointing to that location. So you can write PTR start. So we need to assign value here. So PTR length not start. We need to assign value here. So this is PTR length. So value will be assigned here. And from here, here. So that location is PTR length. So this statement we need to write. So now PTR is 2000 length. PTR is on 2000 length. What is its length? That is 3000 length. So PTR will be going to 3000 length. Which is this. And its length is 1000 length. So by this, what we are getting? 4001. And that will be assigned to PTR length. So PTR length is now 4000. So it means this is disconnected and it is pointing to this one. So this is first node now. This is second node and this is pointing to this third node. And it is deleted. Now we need to delete it physically. So that this memory can be utilized by any other program. But here you can see, now we cannot access 3000 from anywhere. Because 3000 was written here and we created it. And we assigned this value from here to here. Now, before executing this statement. A year here was 3000. That's why it was linking to this and it was linking to this. So before executing this, you need to use one more pointer. Let's say T and inside T you can assign PTR length. So this is T pointer, it will be having 3000 length. That is PTR length. And now you can execute this. So PTR length will be having this whole problem. So these are disconnected. This node's address is available to P and here you can write P and do this only. So this way this delete after operation will be performed. So this way I explained you all three logics. First was delete first, second was delete last and third was delete after. So this way I hope this works out. We can implement all three functions with the help of scene language. If you want to watch their algorithm or their implementation with the help of ID, that is explaining all the functions implementation together. So you can go to description of this video. You will find links of theories and while playing that playlist, you will need to search the related video and you can watch the complete program or complete algorithm. So I hope you understood whatever I explained in this video. Thank you for watching this.