Advanced Data Structures: Different Operations On Doubly Linked List
Advanced Data Structures: Different Operations On Doubly Linked List
M.Jeevana Sujitha
Asst Professor
To understand the pros and cons of doubly linked list when compared to
singly linked list
temp = head;
while(temp != NULL)
traversing to the end of the
{
linked list
temp = temp->next;
}
Suppose you want to delete the second node from the list.
Start traversing the linked list from the head until the position = 2 of the
node to be deleted.
Let the node at the position 2 of the list be temp.
Assign the next pointer of temp to temp's previous node's next pointer.
Assign the temp's prev pointer to temp's next node's prev pointer.
Delete the temp node.
“C” Routine for deleting an element from
the specified position of a linked list
temp = head;
for(i=0; i<position ; i++) Finding the node position
{ which want to delete
temp = temp->next;
}
if(temp != NULL)
Assign the next pointer of node to be
{
deleted to its previous node's prev pointer
temp->prev->next = temp->next; and Assign the prev pointer of the node to
temp->next->prev = temp->prev; be deleted to its next node's next pointer
free(temp);
}
“C” routine for displaying the data in
forward direction
Doubly linked list can be used in navigation system where both front and
back navigations are required