Linked List Operations
Linked List Operations
Linked List Operations
There are various linked list operations that allow us to perform different actions on linked
lists. For example, the insertion operation adds a new element to the linked list.
Here's a list of basic linked list operations that we will cover in this article.
• Traversal - access each element of the linked list
• Insertion - adds a new element to the linked list
• Deletion - removes the existing elements
• Search - find a node in the linked list
• Sort - sort the nodes of the linked list
Things to Remember about Linked List
• head points to the first node of the linked list
• next pointer of the last node is NULL, so if the next current node is NULL, we have
reached the end of the linked list.
In all of the examples, we will assume that the linked list has three nodes 1 --->2 --->3 with
node structure as below:
struct node
{
int data;
struct node *next;
};
temp->next = newNode;
head = head->next;
temp->next = temp->next->next;
// Search a node
bool searchNode(struct Node** head_ref, int key) {
struct Node* current = *head_ref;
if (head_ref == NULL) {
return;
} else {
while (current != NULL) {
// index points to the node next to current
index = current->next;