DOUBLE LINKED LIST (CREATE AND DISPLAY) - 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 sessions we have seen the circular linkedlist now in this session we'll go with the another concept that is double linkedlist right the name itself indicates here we have to establish two links for every goal so till now we have used a normal link released that means a single linkage where every node is having one data field other one is a pointer fill or an address field which holds the address of the next node now in this double linked list the name itself indicates everyone will be having to address fields to address fields that means every node will link to different nodes so what is the next load another one is the previous book see some how to represent these double liquid is a node in a WP list so a representation of a node in the double encouraged is this one that means so it is a node which consists of three compartments the middle one is the data the middle one is the data so next rightmost one is the next leftmost one is a previous right so see this is the address field and this one is also the address field right so this stores the address of previous moon enters of previous mode and this holds the address of next more right this holds the address of previous mode this holds there are some flexible know if it is a starting element if it is the starting element so that means if it is ahead then the previous so there will be no previous room okay so this is ahead that means the starting element so it doesn't have any ignored the previous one so there will be no link for the previous node so that's why here the previous must be equal to now if it is ahead if it is ahead here if it is a thing so we know that attain is a last tillman time is a last element so if it is a last element then there will be no other mode so the next field will be now next will be right hope I hope you understood this one if it is a worldly single node then previous three will be null and the next will be holding the address of the next node if this load is a last load that is attained then previous will hold the pre address of previous load and next there is no other mode so next will holds the null value right then so this is the representation of a lower in the whole linkedlist EE so here we are using two links two different things so that's what we are using this double linkedlist right now let us create a structure for this load so I hope you create a structure for this mode so here there are two fields one is data two are the adjustments simple so we know that's more which we have created for simian village so then we have to use start lower start radius so a central Frenchy load next int data so in degenerate character water baby again start nor start next so this is the structure furthermore in EE greenest okay so three three fields money to other address fields previous and next and another one is a data right so hope you understood this one so if it is clear then we can write the code very easily for creation and display so in this session we will see the two operations that is creation I mean how to create a double linked list and how to display the loads of it of a linked list so that will be very easy if you understand this concept right now let us move to the operations yes so first one is create so how to create the North Sea we know that here also the same concept which we have studied in the single liquid list so here also we have to allocate the memory but using the dynamic memory allocation so here we can use the nu is equal to first first statement nu is equal to spent the most time malloc sizeof node so automatically the point the errors will be assigned for this new now what we have to do we have to read the value data data so scanf percentage D amber same plane so if it is an indigent we have to use this percentage D if it is a character we can use a percentage see right now we have a value and load no what we have to do so we have to place this value in the moon so whenever we execute this one this will be created C so this is the previous this is the next this is the data and this one is the new right now value if we take M as a value right now we have to insert that one so it is a first element right it is a first element so the previous will be 1 and next will be none because only whatever it is there so that's why we can simply write it as new of previous is equal to null newer data is equal to than you so we are placing the libel you off next is it word to open this one three statements so initially it is null it is temp it is not right so we have creating only one element so that's why we're just placing both the null values now so in the second iteration we have to leave another value then we have to place the address in the next so that's why here we will check the condition see if head is equal to is equal to null so initially consider the head so we have to consider the nodes head tail em so all are the pointer values all over the pointer variables so that's why simple similar to our new right if it is equal to is equal to null then we have to assign the head that day to this same room because initially this both are loved so 10,000 points to any node similarly tail doesn't points to any would now we have inserted we have inserted one element so automatically the head that day will be pointing to the single node the same that's why we can save the head is equal to new pay is equal to u so automatically after executing the statement so this is a head this is the tape right so all the three you can detain all are pointing towards the same node now yes now this part will execute if in the second equation from the second intention right so after completion of the first equation second iteration it will again read the value so 20 if you read a value 20 and one more node is created here right now new is this one so this is not in you this is only ten tenten see this is the second iteration second information so 20 is the event so initially after reading the value new previous is equal to null so here it is null data I is equal to value so here 20 will be placed next is equal to Mun okay now right then see if hand is equal to is equal to null head is not equal to null because so let it be a thousand is the housing is the address of this one and this one so head is pointing to the thousand member location so it is not equal to null so that's why this is conditionally face automatically else part will be executed in this but we have to write what we have to write so we have to place the previous field that means the previous address field should be holding the address of the previous one right and in the head the next field next take a sphere should holds the address of new hope you understood right so this should not be done and this this should not be done because this is not a single element it is having the second element so first element how to store the address of second element and the second element in the second element it should holds the address of first element in the previous field right so that we have to do that see first pay off next a of next so take off next is equal to day of next week's this one they pay off next what it should be and of next mm should be placed here right so mm because mm is the second note the address of second note should be place in the enter speed of first moon so tale of next is equal to new tariff next is equal to new now here we have to place in the null place we have to store the address of head right so here it should be thousand because this is the previous one because this is the previous one all right this is the previous one now what is the position here new of previous new of previous is equal to take why we have to take the table I should not take the head this is the question because this is the second language if you go with the third element if you place the address of I mean address of head there automatically it will be song so we have to move the tail from first element to second image so the next one is a is equal to nu n is equal to MU so automatically here the tail will be released and it will be a same here okay so hope you understood this one now see this is the second iteration in the third iteration if you place thirty if you place thirty so one more node is created here so one more node is created here right so see 30 new previous is equal to null so this is so it is new right it is New York Delta is equal to value so 30 euros next is equal to the hub okay fine if head is equal to is equal to null and it is not equal to none so else part will be executed pain of next equal to noon what is the thing taken off next so this one take it off next see this is the next path so take off next is equal to let it be the address is 3000 take off mix equal to new so that means 3000 will be placed here so automatically anything will be established from here to here next new of previous what is the new previous gave new of previous is equal to thing is equal to tail that means two thousand so here we have to place to those okay next tail is equal to you take is equal to MU so thing will be replaced it here and the tank will be here right so whenever you place the two thousand here a link will be established from previous node two currents on to piƱas mode right so this is how a doubly linked list can be created okay this is also very simple concept so all these should be a victim under some loop right so iterations iterations so we have to repeat these statements until we want to exit right so hope you understood this create method create orgy it's simple logic right so I am NOT giving you the program completely just I am explaining the logic so if you draw the diagram and if you if you trace the every statement automatically the very easy right so hope you understand this create method create operation now we will go with the display operation so once you created this one then how to display the elements of a double link register so that is a normal logic which we have seen in the linkedlist and the circle interest see the same thing we will follow so hope you understood this create how to create a double interest see the second one is display so to display the elements of a link released so we will go with the this one so we have to travel this one so first just just say head to temp because we have to travel from first node to the last Pole so why why temp of next not equal to null temp of next not equal to null or simply we can write M not equal to null so anything is no problem right so temp of next not equal to null or m dot equal to null all right so if you write the temp M of next not equal to null it will display up to here and out of the loop we have way again the display the temp of data so if you write the temp dot equal to L it will move until the last last load so here what we have to do we have to print every element what is he even here printf percentage D M of data right so if you want to print the data Stephanie's temp of data and after printing the element we have to move the temporary bin so temp is equal to temp of next so this is a simple logic for displaying all the nodes of a double degree list so in the first one M 1 equal to first attempt is equal to head so here the temp will be here so temperament equal to love so temp not equal to null so thousand here every squad thousand so not equal to null is true so it will display 10 next temp is equal to temp of next so temp now 10 is equal to temp of next so what is the temporal fixed mm so temp will be here at the 2000 position now again tempo equal to level so 2000 or equal to null so obviously temp of dead typing if we enter into the loop and if you please temp of data so 20 will be predicted next MV is equal to temp of next what is the temp of next 3,000 temp of next this is the temp of previous this is a type of list this is a temp of data so tempo flex is 3000 so it is a same to temp so now the temp is assigned to the next element template so M not equal to rather 3000 or equal to 2 so temp of data will be printed so M power data 30 will be printed temp is equal to temp of next so what is the temp of next now so M is equal to novel again 10 not equal to null so condition false automatically comes out from the tool right so in such a way we can display all the elements of a all the roots of a double linkedlist right so the concept is very easy so try to understand this one so try to write the logic try to try to drive the program and execute the program and if you are having any doubts regarding this create and display operations or any doubts or queries regarding this session feel free to post your thoughts in the comment section so the term indefinitely trying 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
Info
Channel: Sundeep Saradhi Kanthety
Views: 32,082
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, data structures, arrays, lists, stacks, queues, trees, graphs, primitive, non primitive, linear, non linear, linked lists, ds fundamentals, ds basics, nodes, self referential structures, dynamic memory, structures, list creation, list display, lists operations, interview, placements, cse, circular linked list, algorithm, program, implementation, computer science, double linked list, previous node, address of previous, address of next, create, display
Id: nZua36vQkkY
Channel Id: undefined
Length: 21min 25sec (1285 seconds)
Published: Mon May 27 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.