Explain Linked List Operations in Data Structure | Data Structure Tutorial
In this article, you will learn about the different linked list operations i.e insertion, deletion, and traverse.
There are multiple linked list operations in that the user can perform various actions on the linked list. For Example, the deletion operation deletes an item from the linked list.
The linked list operations we will discuss in this article are:
- Traversal: It means accessing each element of the linked list.
- Insertion: It means inserting a new element inside the linked list.
- Deletion: It means deleting an item from the linked list.
- Search: It means searching a node in the linked list.
- Sort: It means sorting the element inside the node of the linked list.
Points to Remember:
The node has two parts:
- head points to the first node of the linked list.
- The other part is next and it carries the address of the next node.
Traverse a Linked List
We can easily display the contents of a linked list. It keeps moving to the next node and displays the contents of the linked list.
Insertion Operation:
- Inserting an element at the beginning
- Allocate the memory for a new node.
- Store the data item
- Change text of a new node which will point to head
- Change head to point the newly created node
- Inserting an element at the end
- Allocate the memory to a new node.
- Store the data item
- Reach the last node of the linked list
- Connect the next of the last node to the newly created node
- Insert at the Middle
- Allocate the memory to the new node
- Store the data item
- Traverse to the node just before the position of the new node.
- Connect the next pointers to include a new node in the middle of the linked list.
Deletion Operation:
The deletion operation can happen either from the beginning, from the end, or from the middle.
- Delete from the beginning: It points the head to the second node.
- Deletion from the end: Go to the second last element and change its next pointer to null
- Deletion from the middle: Traverse to the node before the node to be deleted and change the position of the next pointers to delete the node from the linked list.
Search an Element on a Linked List
The element can be searched from the linked list using a for loop with the help of the following steps:
- Make head the current node.
- Run a loop until the current node is NULL because the last node points to NULL.
- In each iteration, check if the key of the node is equal to the element. If the key matches the item, then it will return True otherwise it will return False.
Sort the elements of a Linked List
- Make the current node as head and create another node index.
- If the head is full, it will return nothing.
- Else, run a loop till the last node of the linked list.
- Repeat steps 5 - 6
- Store the next node of current in the index.
- Swap the current with the index, if the current node is greater than the next node.


