DOUBLE LINKED LIST (INSERTION AT BEGINNING,ENDING,SPECIFIED POSITION ) - DATA STRUCTURES

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in the previous session we have started the double linkedlist so where every node will have two links one holds the address off of the previous mode and another really holds the address of the next node so that's why it is called as a double link register so there we have already covered two operations that is how to create the link doubling the list and how to display the non-profitable linguist in this session we'll go with the another operation called insertion so which we have seen in the little signal equidistant circle introduced so insertion all the three cases that means inserting the element at the beginning inserting the element at the ending and inserting the element at specific location let's specified location right position that were linked list right now so when I say take one liquid mistake then we will place the not see let us have so you can be having the Cooling's the forward link and the backward leg let us take the three modes first let us consider only the three nodes so the end of this loan is thousand two thousand of this so let me be ten funky and so here the previous image so it is null the next statement address that is two thumbs in the previous segment address thousand the next element address three thousand the previous 11th address two thousand and next there is a last node so we will be finished tomorrow and this is the a and this one is the head right now the question is if you want to add an element that makes insert an element at the beginning position C so again draw this one I'm sorry Hey let us sit right here so this is the insertion the in session first at bringing in session and beginning so if you want to add this one see add the in read so far this but first we have to allocate the memory the emitter this is the common T mu is equal to struct node star minoc size of start over right now a memory is allocated for the new so let it be some 500 500 okay now so this will is a previous data next and this is the new this is the new now see right here itself this is now what we have to do phosphor how to read an element so scanf % HT ampersand ready so a value is incentive so let it be some 5 the value will read from the keyboard is 5 the first step is just press the value in the data so the new of data is equal to value so automatically 5 will be placed here right hooks to this one then we have to fill the previous moon and the next node so this is if you insert an element in the the previous four will be loved so new of previous is equal to none so automatically here we can place next one should be stored in the next and recipe so here the address of hand should be placed so new of next is equal to hem so automatically thousand will be stored here so a link will be stored here now that ever sink also to be contained that means head of previous so this is the previous day attack next head of previous should force the interest of new so head of previous is equal to so after X giving this one this love will be replaced with the address of that is 500 so hope you understood this one now we have to move that 10 because here so whenever you place this form automatically another Glee the reverse sleep will also be connected established now here this is the second element now head is pointing to the second element so we have to move the head to the first in so head is equal to a new that means here head will be replaced with I mean head will be moved to new right so this is a simple logic for inserting an element and the beginning of it doubled in finished so here we have to take care about the address we have to store in the previous field and it has to be stored in the next field so that means for every node there must be two connections one to the previous under to the next that should be remember carefully right right hope you understood this one it's a very simple logic now let us move in the another case if you want to insert the element and the bill last that means n see second one nd so just we will and there's all these things okay when there is all these things let it be the first load so mouth should be placed here and this is the head and that is a take mob if you want to insert the element at the end that means here we have to place right here we have to place so this is a new book this is a you know so whenever you allocate the memory some memory will be allocated here so I have a four thousand is a memory allocated for this node now we have to read the value so if you read the value some 40 right if you really value some 40 so first place value your data is equal to a value automatically 40 will be placed here because this is the data previous and next no we have to establish the connection between the previous take node and the newly inserted role right now see so as if you insert that load that will be the last loop because we are inserting the load at the end position so this is the last node so if it is the last node then we know that then next to field the address field the next address field should be initialize it to none because it doesn't points to any other mode so new of next is equal to MU of next is equal to now then what were the previous one knew of previous so it should be it should hold the ends of previous mode what is the previous one take so the new of previous is equal to 10 so here and after doing this one new of previous is equal to thing this 3000 will be here so a link will be establishing here right and one more statement should be written because the reverse connection also to be established because he obtained your previous is null that means it doesn't holds the address of the last one so it should hold the address of last one so that's why what is the feel here they know next so previously sorry previously this love so which we have to replace with a new area so the new value is replaced so here now will be replaced with the headers of new that is just inkless photos so automatically a link is established here itself right so hope you understood now we have to move the thing because teh is assigned to the last but one so we have to change the tape so they is equal to uni automatically here the day will be replaced and here it will be so this is a small logic simple logic for inserting an element at the end position so if you draw this one and if you trace one by one automatically the code will be very simple right sorry now let's move with the third case that is inserting the node a specific location third one specified position right so here we need to read the two inputs what is the value of the what is the position right now we have to read and one more thing that is a position position so let us take the position two and the element is 25 all right the element is 40 further the position - so here we have to insert this 40 file in opposition to so here the position of this one is 0-1 and so here we have to insert the node right so first of all let us turn on this one to that position so I saying temp is equal to head so initially the temp will be here but I is equal to zero - that position minus 1 I plus press we need to move the temple 100 M is equal to temp of next so for after first iteration the temp will be moved to here the temp will be moved here right now after the second iteration the condition fails comes out from the loop now we have to replace all these things so first we will place the data so new of data is equal to value that means here 25 will be placed so this is the new this is the new so 25 will be placed in the value next we have to place the new of next new off next so you know of next so watch what should be fill here your next should be 3,000 which is nothing but temp of next right go get that fills me off next that we see course address of the next next segment what's the next gen 113 what is the address of 33,000 which is nothing but temp of next so simply we can write temp of next then so here we can have same okay here we can have a print on same now we have to replace this one this one because this should be so what about this one temp of the next of previous is equal to temp of next miss 3000 3000 previous 2000 is equal to here it should be new so 2500 okay so it Matt's here okay it Maps here no we have to replace this one what is this one so new of previous new of previous okay the new of previous must be filled with temp of previous okay the temp of previous so on we can simply replace this one see amp of next here it should map the it should point the address of new so here we can write temple next temp of next or do you simply here we can get 2500 okay it Matt's here okay know what should be place it here it should holds the address of previous one what is the address of previous four mm what is the mm mm so knew of previous is equal to M your previous is equal to temp that means here the temporary variable the temporary variable means 2000 so 2000 will be placed here in this position so okay so this is how we have to find the code for inserting the element and the specific position okay so first we have to allocate the memory for the new and then we have to read the value we have to create the position and then we have to travel until the position minus one and then so this is the new world so we have to fill the previous new of data enough next so here first you have data is equal to value so front if I will drink it I mean stored there then yours next what is the new of next it should hold the address of the next one what is the address of the next one is 3000 which is nothing but temp of next so 10 companies next improve next up previous that means this will this finish will be a I mean next the previous field of next lower should be holding the new from F of next stop three days temp of next is 3000 3000 of three days is 2500 is equal to this position is equal to new new means 2500 so 2500 will be replaced next impulse next F of next mix this field should be replaced so before it is allocated with the next one that is 3000 so f of X is equal to new so to now you have previous what about in Europe previous new happiness is equal to Emperor so 2,000 will be spoke right so hope you understood this one so don't get confused simply a rather diagram the other loans so that everything will be clear right so if you are having any doubts regarding this session feel free to post your thoughts in the comment section so that definitely I will try to clarify all your doubts and if you really understood my sessions like my sessions share my sessions with your friends and don't forget to subscribe to our channel keep following thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 34,735
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, data structures, fundamentals, basics, arrays, lists, linked lists, stacks, queues, trees, graphs, searching, sorting, insertion, deletion, operations on data structures, primitive, non primitive, linear, non linear, binary trees, binary search trees, LINKED LIST, NODES, ADDRESS, INSERTION, BEGINNING, ENDING, SPECIFIED POSITION, ESTABLISH LINK, SINGLE LINKED LIST, CREATE, DISPLAY, DOUBLE LINKED LIST, PREVIOUS NODE, NEXT NODE, HEAD NODE, TAIL NODE
Id: JZ8Gba9jnF0
Channel Id: undefined
Length: 18min 57sec (1137 seconds)
Published: Tue May 28 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.