DS Doubly Linked List
DS Doubly Linked List
Linked List
Basic Operations
Following are the basic operations supported
by a list.
Insertion Operation
Following code demonstrates the insertion
operation at the beginning of a doubly linked
list.
Example
//insert link at the first location
//create a link
last = link;
} else {
//update first prev link
head->prev = link;
}
link->next = head;
//point first to new first link
head = link;
}
Deletion Operation
Following code demonstrates the deletion
operation at the beginning of a doubly linked
list.
Example
//delete first item
if(head->next == NULL) {
last = NULL;
} else {
head->next->prev = NULL;
}
head = head->next;
//return the deleted link
return tempLink;
}
Example
//insert link at the last location
//create a link
last = link;
} else {
//make link a new last link
last->next = link;
last = link;
}
Print Page