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 linker list concept so in the clicker list we have seen how to create a list so how to display the notes in a list so in this little list we will handle with the nodes in terms of nodes right so out an element it's in load so node consists of two things one is value another one is the address of the next node so we have created one structure right so there we have created one self-referential structure for every node and then we have created the linked list so you can follow the previous session for understanding the introduction and the creation of a list now in this session we will see the insertion operation so how an element can be inserted in a linked list existing increased right so here we are establishing a link between one load and another know so all the nodes are need not occupy the contiguous memory locations that we have seen in the previous sessions right so now let us see the insertion of an element to the existing linkedlist so link released so here we see three cases the first one is insertion of element and beginning at the beginning right second case is insertion of an element and ending similarly insertion of an element and specified position so these this cases we can we'll see not right so one is inserting an element at the beginning of the linguist and the second one is the insertion of an element at the ending of the linguist third one we have to specify some position and we have to insert the element at but that particular specific position right now let's see one by one let us say one example and then we will see that now so just to follow the previous session for creating a list so let it be first we have created a list with four elements so first element second element third event for thing see every element and in every node is having to fills for this data let it be 20 30 40 and 50 so the memory occupied here is thousand and in the memory address address of the node is thousand this is 2000 this is three thousand and this is four thousand so we know that every load consists of the second field that is a address of the next node so here 2,000 will be saved here right so enter soft next node here the address of 40 that means till dozy here the address of 50 some 4000 whatever the last element we know that the last element the address will be null so if the if any normal consists of the Maumee in the place of address that we can consider it as a last element of the list right so this this is a head this is a head and this is a take now for everything we have to first take the node and then we have to insert it so further for every node we have to allocate the memory by using dynamic memory allocation right so here we have to use the dynamic memory allocation for allocating the memory so which overcomes the drawback of an array right so so in the three cases insertion at the beginning insertion at the ending inception at this specific position first we have to allocate the memory from the load and then we have to read the value so this is a common statement for everything so forth in the three cases so start node star so this is a memory allocation so we have to use a Milaap for memory education so we have to specify the size of so that means how much memory to be occupied so that will be allocated to the element you know so first insertion and beginning insertion at the beginning now see first let us write the output so that we can easily identify see so 2013 15 this is the last tenants of this is this is right and she element if you add a word here it will be 10 and this will be thousand so this will be the head this will be the tail so first this is the output right so after inserting and node to the existing list so which is M right so the element is M so M will be inserted at the beginning and for this node then address must be the next next node address that wins 20 so 20 address will be here C will be some 500 some thousand so this is the address location right so this is the output for this output what we have to do so first one out allocated memory for the element and now we have to read the element so for reading the element simply we can write the scanner scanner percentage D Amazon well let it be value in the value that is hello okay so now here after reading the value is equal to think now we have to place that in the beginning position so first let us see new of data it should be filled similarly New York off next it should be filled so in the data the value should be there in the list the address of the next node must be here so initially this one so new data is automatically temp so we can directly say make new off next so in the new off next here we have to get the address of previous node so my centers of previous no previous mode head off next right so what we understood here head you know next is equal to n already thousand will be this value if you right hand of next if you write head of legs then two thousand will be here right so head that means automatically the head address will be assigned to you off next so automatically this will be happen and the head will be placed in here itself so we are just inserting the element get there beaning so head should be to the first element so you can directly assign the new is it by hand is equal to so the three statements the three statements are required to get this all right so hope you understood so initially this one so initially this value is the list so if you want to insert at the beginning that is n by 10 the L must be the first node and the address should be the 20 then the node 20 address should be pleasant first node so for this we have to write the new of data is value and you have flexed so this is the new off next new off next so even you have mixed we need the head Edna's so previously this and is ahead so hand address should be stored in the openings so new off next is equal to three so this means the connection is established between the first element in second element and now head is pointing to the second element after insertion so we have to hold a head to first element so head is equal to right so hope you understood this one inserting at the beginning now let us move with it next one inserting at the ending so this is the head this is the thousand and if you want to insert here right so here if you want to insert an element 16 if you insert a robot sixty and then any right another ending position so initially the list you see this one if you insert an element sixty at the end position so the output will be this one now we will write the pool so this is a common thing first we have to allocate the memory for this new node and we have to consider the value we have to take the input for a value and then we have to place C first automatically you can simply write the new off Delta is equal to value so automatically that will be there now now see this position so what is this position this one is new address and off move and as of new should be placed in hey see initially the tail is 50 so if you want to insert a new node this address should be placed at a off next so aim of next is equal to new automatically the node new address will be saved into the a 150 right and the new of list should be nothing because it is in last in so new of next is equal to knowledge right so with these statements the node is created but the tail is at the last but four position we have to move this table to last last word so J is equal to you take is equal to new right so this is the statements simply we are adding the element at the end so that we are so we are replacing this null with the new road address so obviously hang up next is equal to new a of X is equal to new and a new of next new of next because the new node itself is a and they wind right anymore so that's why we have to fill it with normal a is equal to Rho will be rose at a center last but one element so tail should be positioned with pointing with last element so 10 is equal to new so what about the element we are inserting the day will be pointing to the particular last statement so this is the simple code for inserting the element at any position right so once we will see all these statements and finally we will implement a program and we'll show you the implementation of a linked list so we will see the create display inserting at the beginning inserting the ending setting at the specified position also in the next sessions we will see the deletion part also right so let us see the third one a specific position specific position right now let us see this one now so let us say one second I write it so that so here 20 30 35 40 50 so here so the address is thousand 2000 3000 4000 5000 so here it is now five thousand now the position is mm here let it be some fight 2400 some other location okay so that should be here 2500 right so simply we can see this one so if you want to insert at the position 2 so here position is equal to 2 and the element is equal to sorry value is equal to 35 so value that if I should be inserted at position 2 here also we can we can consider the index value from 0 itself so from 0 the index starts that means the index of first node is 0 second node is 1 third 1 is 2 and so on so here see initially this one so this is our list in this list at the second position we have inserting the element and the second element we are inserting so simply we have to establish the link see first consider the temporary variable because we will not move the head right we need not move the head just consider the temporary arrangement so this is the head this is the a so first we have to reach until position minus 1 because this position should be changing right previously in the core 30 the address of next that means the 40th enters the node 40 address is saved in the next of 30 right now it should be changed to new road the new node address should be sent to the position minus 1 row side we have to travel up to position minus 1 right now let us consider temp is equal to head a saint some the head value to the temporal now consider the position also so here we have to read again scatter the percentage D and present position so value here is sanctifying the position is two right now using two statements but I is equal to 0 because index we have you have said that so I guess then position minus 1 I press press so until it reaches the position minus 1 so just move that means the temp is equal to temp of the next so next centers next status it will move until it reaches position minus 1 so I'll just write okay fine so now the iteration is here itself so if you place this 2500 in this position the position of fortieth code will be erased right so we have to follow the steps first we have to place this 3000 in new of next so simply one statement is former that is new of data is equal to the value this is common now next one here in the pro 30 in the second field of 30 it should be the address of new rule and and in the field of new role in the second field of new world it should be the address of next what that means according so first if you place here right if you change this one right if you change this one we can't place the address of 40 in the new rule right so first we have to assign the north 40 address to the middle so new of next is equal to M of next so newer flexed is equal to temp of next so no connection is not disturbed no correction is must not disturb no place this with the new road enters so next m of next is equal to new dep of next is equal to new temp of next is equal to u right so these two statements are very important we have to follow the same order right so this one if you reverse this one that means first if you remove the temp of next is equal to new so if you perform this statement first automatically here it will be 2500 right it will be 2500 and this will be nothing and what it this should be placed here because we lost the address of the 40 we lost the enter so possibly then if you implement this statement tempo flex discontinued before the statement right so that is why first you have to establish the connection so that's why moves next your next is equal to F of mix that means print 3000 will be placed in the new of next and then F of next is equal to so 2500 will be placed in here right so this is the code for implementing the insertion operation at the middle right so hope you understood this one so the three cases so insertion of an element at the beginning insertion of the element and ending and insertion of the element in the middle position I mean specified position right so if you understand this list concept it is very very easy to write the code so foster write on the input and draw the output based on the output if you write the code then it will be very easy okay so we know the sequence of steps what could be first and what to be next so let us up here in the next session we'll go with the deletion operation so in the deletion operation also we have to see the three cases deletion deleting the element from the beginning deleting the element from the ending deleting the element from the given position specified position right so that that sessions will be in the next one so in this video so I will just give the link of the first introduction and the creation of a list in the description section right so just go through before watching this insertion so it will be very easy for you for writing the core right so let us stop here if you really understand my speed videos so like my videos share my videos with your friends and if you are having any doubts regarding this link at least feel free to post your thoughts in the comment section so that I will definitely try to clarify all your doubts and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 100,885
Rating: 4.8560848 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
Id: P9AKKKvPYiE
Channel Id: undefined
Length: 23min 17sec (1397 seconds)
Published: Tue May 14 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.