 Hello friends, I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain you how to write an algorithm so that we can start a singular equation. So before starting the algorithm, let me explain this diagram so that you can see we have three nodes and each node is having two pipe one is in two and the other one is next to the other. That will be holding the address of next node and initially we have start that is having address of first node. So I already explained this diagram in detail in my previous video. So if you want to watch that video, you can go to description of this video and you will find link of a playlist. So in that playlist, I have some of all the videos related to our data structure. So you can find that video here and you can watch that. Now I'm going to write an algorithm so that we can start a list. So I'm going to use this diagram for reference purpose. So name of algorithm will be solved. It will be having three parameters as start, second will be info and then link. So start is having address of first node, info is the value part of each node and link is holding address of next node always. So we are going to use three links in the algorithm. So step number one will be set P1 equals to start. So start is basically having initial address of node one so that is stored in P1. So this is step number one and step number two will be repeat. So I'm going to start a loop. So repeat steps. So we are going to start repeat certain steps. So that will be P2 pipe while P1 node equals to null. So if P1 is not equals to null, then this loop will be iterated and it will be repeated. Now step number three will be set. So here we need to set one more pointer that is P2. So here P1 is pointing to start and P2 will be pointing to link of P1. So starting from this point, so P1 is pointing to one terminal to one and P1 is not equals to null then link of P1. So P1's link is 2001 that will be stored into P2. So P2 will be pointing to second node. Now step number four. So at step number four again, I need to implement a loop. So repeat step. So here we need to repeat some steps. So instead of step I am writing set because I am going to write some steps like P2 here along the F condition. So those we are going to repeat. So repeat step while P2 not equals to null. And what set of statement will be repeated I am writing that. So now we need to implement if addition. So if info of P1 is greater than info of P2. So P1 is pointing to personal P2 is pointing to second node. If information part that is 10 is greater than info of P2 that is 20 so this condition will be true. So when this condition will be true then we need to implement these three operations A, B, C and these three operations will be swapping of these two values. So let's say this is having 40. So 40 is greater than 20. So in that case we need to swap these two values for the 20 and come here 40 and go here. So right now I am writing set P equals 2. So P is a technically variable that says 4 values info of P1. So info of P1 will be stored into P2. So P2 info will be stored into P1 and that is set info of P2 equals to P. So these are simple swapping statements. We are basically swapping values of no one will go through. So 20 will be come here and 40 will go through. Then end of it. So this will be stored here. Then we need to complete this loop. So after completion of this if I am writing set P2 equals to length of P2. So this statement will also repeat with this loop. And after this I can write end of set for you. So this set number for you will end here. So why I mention this because P2 is right now pointing to this position. So first we have to complete this node with this and then this also. So for that node I mentioned this. So it will be pointing to P2 and P2 which is complete with the value of P1. So basically what we are doing we are comparing first node value with all other nodes and we are trying to take out the smallest number that can be stored here. And we will pick second node and the second node value will be complete with other remaining nodes and the next smallest element will be stored here. So this will be stored here. Now after this end of set number for you. I need to write next set. So that is set number 5 set P1 equals to length of P1. So P1 will be moved to next location and after this I can write end of set for you. So this loop will be terminated and then set 6 will be end. So now I am going to execute the statements which are mentioned here so that you can see how this length list will be sorted. So let's say 14, 20 and 30 are the values. So P1 is pointing to 1001 due to this. Then this condition is 2. P2 is 7, 2001 due to this. When P2 is not equal to 0, then compare this. In form P1 is greater than H4 P2. So 40 is greater than 20. Then we need to swap the values. So here 20 and here 40 will be stored. Then only P2 will be moved. So P2 is right now pointing to this location and it's latest 3001. So new value of P2 will be 3001. Because this is in a loop. This is in a loop which is repeated. So P2 is not equal to 0. So this value will be compared to this. So 20 is less than 30. So this value will not perform. Then P2 will again include link of P2. So that is not. So this time P2 is not. So this loop will be translated. Now we need to move P1. So P1 will be pointing to link of P1. So P1 is this. It's latest 2001. So this time P1 will be pointing to this location. Now check this. It is true P1 is not equal. Now P2 will be related from link of P1. So P1 is 2001. That is second loop. It's latest 2001. That will be P2. So P2 will be related from here. Now P2 is not personal. Now check this. Inform P1 is 14. Inform P2 is 13. So it is true. Again swapping will be performed. So 13 will come here and 14 will come here. So this way you can see changes happened. That P2 will move to link of P1. So P2 is pointing to 2001 and it's latest month. So again this is pointing to null condition. So this condition is false. Now P1 will move to link of P1. So P1 is pointing to 2001. It's latest 2001. Then this condition is true. P2 will be pointing to link of P1. So link of P1 is null. So P2 is null. It means this loop will not repeat. It will be terminated again P1 will move to link of P1. So link of P1 is null. So it will also not repeat. So this way all the steps are formed and you can see link list is sorted and ascending. And if you want to perform sorting and ascending model, you can just change this data size. So all the values will be arranged. So this way I hope you understood how we can hide and use them to sort our link list. And if you want to watch more algorithms related videos, so you can go to description of this video. You will find links of playlist related to data structures and I will come and implementation of DSA to this language. So more source playlist, they contain several videos related to data structure so that you can learn DSA well. Thank you for watching this.