Linked Lists Algorithm
Linked Lists Algorithm
Linked List is a sequence of links which contains items. Each link contains a connection to another
link. Linked list the second most used data structure after array. Following are important terms to
understand the concepts of 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.
LinkedList − A LinkedList contains the connection link to the first Link called First.
As per above shown illustration, following are the important points to be considered.
Doubly Linked List − Items can be navigated 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.
Basic Operations
Following are the basic operations supported by a list.
Insertion Operation
Insertion is a three step process −
Deletion Operation
Deletion is a two step process −
Navigation Operation
Navigation is a recursive step process and is basis of many operations like search, delete etc. −
printf(" ]");
}
Advanced Operations
Following are the advanced operations specified for a list.
Sort Operation
We've used bubble sort to sort a list.
void sort(){
tempKey = current->key;
current->key = next->key;
next->key = tempKey;
}
current = current->next;
next = next->next;
}
}
}
Reverse Operation
Following code demonstrate reversing a single linked list.