Doubly Linked List Algorithm
Doubly Linked List Algorithm
http://www.tutorialspoint.com/data_structures_algorithms/doubly_linked_list_algorithm.htm
Copyright © tutorialspoint.com
Doubly Linked List is a variation of Linked list in which navigation is possible in both ways either
forward and backward easily as compared to Single Linked List. Following are important terms to
understand the concepts of doubly Linked List
Link − Each Link of a linked list can store a data called an element.
Next − Each Link of a linked list contain a link to next link called Next.
Prev − Each Link of a linked list contain a link to previous link called Prev.
LinkedList − A LinkedList contains the connection link to the first Link called First and to the
last link called Last.
As per above shown illustration, following are the important points to be considered.
Basic Operations
Following are the basic operations supported by an list.
Insertion Operation
Following code demonstrate insertion operation at beginning in a doubly linked list.
if(isEmpty()) {
//make it the last link
last = link;
}else {
//update first prev link
head->prev = link;
}
Deletion Operation
Following code demonstrate deletion operation at beginning in a doubly linked list.
head = head->next;
//create a link
struct node *link = (struct node*) malloc(sizeof(struct node));
link->key = key;
link->data = data;
if(isEmpty()) {
//make it the last link
last = link;
}else {
//make link a new last link
last->next = link;
//mark old last node as prev of new link
link->prev = last;
}