2.11 Insertion in Doubly Linked List(beginning, end, specific
position) | Data Structures
Jenny's Lectures CS IT
in this video we are going to see the insertion operation in doubly linked list insertion ad
beginning insertion at end insertion at any specific position as well as insertion after a given
position. In this video the data part three parts are there basically basically right we have already
discussed how to represent this node when you are going down a c program right and c in that
case we have n't maintained our tail pointer. In this case the insertion in doubly linked list at end
will take time order of 1 if you maintain this tail pointer. If you don't maintain this then only 3
nodes is there then this this this node and that head pointer you have to store. The drawback is
what this is going to take some memory space right. The list is a doubly linked list so we are
going to define a function you can say a create doubly-linked list right so first of all we're going
to create a node. The syntax we have already discussed many times right right Malik is a
function for dynamic memory allocation how much size you want size for this node.
We have asked from the user using this new printf and scanf the data inserted is 6 and here is 0
and 0 now I want to insert this node into this list so now if head is equal to 0 then in else part
what you will do now is insert a second node in that case the new node will contain 200. Intel
shows how you can exist this part both using head pointer and tail pointer. The same logic you
can apply after this it will ask you do you want to continue. If you press 1 then another a node
would be created and inserted if you press 0 then no extra node was created and only you can
call after that. The main motor is what have you can maintain this tail pointer so high hope you
got the concept now we are going to insert at beginning how you will write this function C so
now let us take this case we have these three node in the doubly linked list head is containing
150 and tail is containing the address of the last node that is 200.
How you can access this part the pointer to this node is head yes we have a pointer so we can
access all the three parts so here what you can write head of previous this part is previous is.
from where I can get this 500 this address in the new node we have 500 so is equal to new
node. how you can store this this this 500 here. Using a ten-pointer temp is pointing here then
here then then here and then finally temp will reach here after that using temp you can access
this part of the list. then you have to Trevor still here like we have discussed in singly linked list.
here we have maintained a tail pointer already right so no need to traverse the list we can
position) | Data Structures
Jenny's Lectures CS IT
in this video we are going to see the insertion operation in doubly linked list insertion ad
beginning insertion at end insertion at any specific position as well as insertion after a given
position. In this video the data part three parts are there basically basically right we have already
discussed how to represent this node when you are going down a c program right and c in that
case we have n't maintained our tail pointer. In this case the insertion in doubly linked list at end
will take time order of 1 if you maintain this tail pointer. If you don't maintain this then only 3
nodes is there then this this this node and that head pointer you have to store. The drawback is
what this is going to take some memory space right. The list is a doubly linked list so we are
going to define a function you can say a create doubly-linked list right so first of all we're going
to create a node. The syntax we have already discussed many times right right Malik is a
function for dynamic memory allocation how much size you want size for this node.
We have asked from the user using this new printf and scanf the data inserted is 6 and here is 0
and 0 now I want to insert this node into this list so now if head is equal to 0 then in else part
what you will do now is insert a second node in that case the new node will contain 200. Intel
shows how you can exist this part both using head pointer and tail pointer. The same logic you
can apply after this it will ask you do you want to continue. If you press 1 then another a node
would be created and inserted if you press 0 then no extra node was created and only you can
call after that. The main motor is what have you can maintain this tail pointer so high hope you
got the concept now we are going to insert at beginning how you will write this function C so
now let us take this case we have these three node in the doubly linked list head is containing
150 and tail is containing the address of the last node that is 200.
How you can access this part the pointer to this node is head yes we have a pointer so we can
access all the three parts so here what you can write head of previous this part is previous is.
from where I can get this 500 this address in the new node we have 500 so is equal to new
node. how you can store this this this 500 here. Using a ten-pointer temp is pointing here then
here then then here and then finally temp will reach here after that using temp you can access
this part of the list. then you have to Trevor still here like we have discussed in singly linked list.
here we have maintained a tail pointer already right so no need to traverse the list we can