Linked list is used to store information at the dynamic level.
Each link stores the address and the information part and links to another node in the list.
Types of Linked List
Simple Linked List − Iteration is forward only.
Doubly Linked List − Iteration is forward and backward way.
Circular Linked List − Last item contains link of the first element as next and and first element has link to last element as prev.
Operation in Linked List
Insertion − add element at beginning of the list.
Deletion − delete element from beginning of the list.
Display − displaying complete list.
Search − search an element from the list.
Delete − delete an element from the list.
//insert link at the first location
void insertFirst(int key, int data){
//create a link
struct node *link = (struct node*) malloc(sizeof(struct node));
link->key = key;
link->data = data;
//point it to old first node
link->next = head;
//point first to new first node
head = link;
}
//delete first item
struct node* deleteFirst(){
//save reference to first link
struct node *tempLink = head;
//mark next to first link as first
head = head->next;
//return the deleted link
return tempLink;
}
0 Comment(s)