Doubly Linked List in C++

Doubly Linked List in C++

Namaste, My name is Nitin Kumar and I am here to write a blog on the topic of C++ Doubly Linked List. We will discuss all the important factors of the Doubly Linked list in c++. We will discuss the Doubly Linked list in c++,  why it is used where it is used when it is used etc.

we are going to discuss Doubly Linked List in C++ operations in a data structures. How to perform all the operations on a single linked list so now so this is about Doubly Linked list in c++  and double linked list what are the advantages over single linked list in a double linked list the main advantage of doubly linked list over singly linked list.

Suppose in a single linked list all ways we can send the control in a forward direction only in a forward direction right! we cannot travel are we cannot travel in a backward direction?

we can’t display the elements from last to first there is a problem we can travel and we can’t move right but here it is in a double linked list as you can move in a forward direction or you can move in a backward direction that is double linked list by the direction in forwarding direction. You can move and in a backward direction also you can process the information so that is a main difference between single linked list and Doubly Linked list in c++ how the notes structure will suppose that in a single linked list node is nothing but writing abstract data type and double linked list also if you want to create a node where it is struck data type only we need to type struct node but how many fields are present how many fields write in a double linked list the node is having three fields then what is having three wheels is a data field this is left link field left link and this is right linkfield now too. Two pointers this one is pointing to and this one is pointing to Samiti is anode structure this is not structured so it is in the struct node definition we have to define 3 variables so fast one is a data type integer it’s a data second one is a pointer pointer what just like in a single linked list only is a struct node type because no one node is Pointing next one more. North Star right struct node star right so this is a simple structure right not structure and next how the completely the single linked list in Data Structure will be right just format how all the nodes are connected and how root node is connected to a mean root pointer is and all the first of all we need to declare a global variable pointer so that is a root variable and initially what is its value null value first we have to declare a variable we have to declare a variable it’s a pointer with the default value is anal nothing but initially it is not Pointing any node that is nothing but list is empty completely list is empty ok and how the node structure will be right nothing but the format of a double linked list will be serious and not construction initially the route variable is Pointing pointing to because no nodes in the list if you create a node first not here it is not will be created nor any data you can play store was this is data and there is no left link why the reason no more notes because it is the first node so here it is first not left link will be null first node first node left link left link is an null value null value and next so what is that right side link that is that will be connected to another note and here it is that node will be created at a particular memory location for example 2046 that we are storing into root so it start Pointing start pointing to first node next one second node we are creating 20 suppose it is a 5048 5048 and this is the first node next node next link is pointing to set this is 5048 this is a connection one way connection two way connection simple this 2046 previous node address we are storing here 2046 so that it is connecting to the previous not and next if you take one more node one more not supposed 30 at some location 7002 so that will be stored here 7002 and next previous node address 5048 will be stored hear sately nodes are there in the list and there is no force not show last node rightlink call Sonal last node write linq is also null first not left link is anal last node or right link is anal because first node is not connected to any previous note and last node is not having and the next node so that is so this is simply how the data will be stored in a double linked list ok first we’ll see how to append write a note to the double linked list so how to append a note to the double linked list that is a first operation we are performing on a double linked list the function name we are writing void append what happened the Global variable to the structure notes structure already that we have created globally so route get memory allocation at some location at some location and what is the initial value is an null value initial value is Null value inside we need to declare one temporary variable struct node star temp variable because we know all the operations on the linked list right so we need to perform with the help of a temp variable only variable the first we are allocating the memory using malloc function we know this using ml ok and what we have to pass the size of struct node we need to pass size of struct node we need to pass then what ml of function will do means it will create a note it will create a node at a particular location location at Temple zakir collecting into temp variable only local variable and Type casting is required so that is struct node star struct node star Mallick size of a struct node so that value we are collecting into temp so temporarily the value we are collecting into variable temp variable temp variable so temporarily it is pointing to next we need to read the data into the node na sir which is the data field sir that we don’t know write because maybe first one is a data field second one is a link field and third one is also lingfield so that’s why in this node every field addresses important every field at this is important is considered this is a data field so data full address you should provide them to data address so this location right for reading so here it is we are asking printer and no data
No data so that we are scanning scanning persentase D temp is Pointing location is a data location and that location address we need to provide address suppose if you give the value 10 the 10 will be stored here then next in this link we have to place null and in this link we have to press null left and right pointers sahiyar here it is time to time to left equals to null and next 1 m to write equals to null so now node is ready here it is left side is a null value and right side is also null value left side is Null and right side is not now not created completely now sir where we have to connect so fast we have to check list is already having some or not if list is already having some of the notes then we should at the newly created node at the end of that existing list or else so we need to connect to the first note that is nothing but root element only if it is a first know how can we check sir very simple suppose if root equals to oh that is nothing but root variable is not. Variable is not Pointing any other node what a node you have created that is the first node so by that time simply at Temple we are assigning to root temp variable we are assigning to root that is nothing but thousand then it start Pointing newly created no that is the If block Adblock will not execute When else block will execute means for reminding node operations if you connect II note note 4 8 9 for reminding notes this else block will execute how it will execute C for example after execution of this app and function temporary will be deleted suppose if you want to add one more Note II Note III note V not so then else block execute SO2 to explain this very clearly I write some notes first I was here second node is this second note and next third node is there just cancer I am writing here 2000 and this node address is a 3000 3000 here 2000 will be stored he connection thousand is here connection 23000 is here so connection and expand mm hair so connection entity now this node address is a null At the seasonal this considered as a from three nodes are there in the list now I want to create IV not so then you will understand clearly ok first of all as Asian append function you are calling the control come inside ferrari variable will be created initially next we are allocating the memory that is nothing but nothing but and not will be created not will be created at some location so that will be collected into temp variable temp is a 4000 temporarily it is Pointing temporarily next one here it is asking to enter the no data and we are saying that time to left is equals to null and time to write equals to null so in that node for was data is a 40 left equals to null byte equals to null node is ready now where we have to connect servers here we are checking if root equals to null value is root equals to null value know because route is already. Which is in the list to list is not empty so if block will not execute then continuation path else block execute in the else block so what we have to do we need to connect IV not here it is at the third note but we need to travel from first location to third location how to travel how to travel means with the help of one more variable struct node star Pizza. Away puppy holding the value P holding the value root value because we should start from the root only no root 2 root 2 value initially thousand root value Bihar collecting and 2P so that is a thousand next we should travel how many nodes are there how many rings are there from first note to that particular node we have to move how to move here it is just while if paid to write not equal to null if we to write not equal to null right means what the next node linked write link if right know Dlink is anal means what we already know that last node or right click will be null Show with the help of that location only so we can travel P to write P value is A Thousand Years thousand to write is it 2000 years it is not equals to null what is it meaning what and what that describes second node is there so that P to write value pay to write value will be stored in to be so is it to write value is a mm mm will be stored here 2000 and next again it will repeat 2000 to write Rs 2,000 to write 3000 is there so it is 3000 will be stored 3000 will be stored for next again 3000 to write is an alias condition true mean write null not equals to Alpha condition false then it will fail city is Pointing we have to create the new no simple thing now how to establish the connection very simple here here you have to store 4000 so that this link will be created and here you have to store 3000 then it will be created sir hauser very simple 4000 means is a temple you know the temple you 4000 4000 nothing but temp value will be stored into this location who is Pointing thousand is AP and this is what right way to write location temp while you will be stored into P2 right next one so this one is over connection now 3000 we need to store into this location the three thousand means what is API p we need to store into this location who is pointing to temp variable is Pointing short temper and what is this location left location or right location left location so time to left P value will be stored into M2 left this is this is right if you want to connect a node at the end of all the notes first we have to travel from first location to that particular location at equal to the last known location and then only two connections because a double linked list ok here it is a right side connection is required and here it is a left side connection is required so this is how to append a node in a double linked list ok and some more operations on a doubly linked list so we’ll see in the next session ok hope you enjoy this video for more videos please subscribe to Naresh additional thank you



Speak Your Mind