A more sophisticated kind of linked list is a doubly-linked list or a two-way linked list. In a doubly linked list, each node has two links: one pointing to the previous node and one pointing to the next node.
Node structure
Implementation of a doubly linked list
Adding an element to the list
To add the first node
first_node->next = NULL;
first_node->data = input_element;
first_node->prev = NULL;
To add a node at the position specified
Temp_node = *first_node;
for ( counter = 0 ; counter<position-1 ; counter++ )
{
Temp_node = Temp_node->next;
}
new_node->next = temp_node->next;
temp_node->next->new_node;
new_node->prev = temp_node->next->prev;
temp_node->next->prev = new_node;
Deleting a particular element from the list
Temp_node = *first_node;
If ( temp_node->data = = input_element )
First_node = first_node->next;
else
{
while ( temp_node != NULL && temp_node->next->data !=
input_element)
temp_node = temp_node -> next;
delete_node=temp_node->next;
temp_node->next=delete_node->next;
delete_node->next->prev=temp_node;
free(delete_node);
}