BCA / B.Tech 9 min read

Operations on a Linked List

Operations on a Linked List in Data Structures:


A linked list is an important dynamic data structure in which data elements are stored in an ordered manner. It consists of nodes that store data and the address of the next node. Various operations can be performed on a linked list, such as adding, deleting, searching for, printing, and reversing nodes.

Insertion Operation:
This involves adding a new node to the linked list.
  • Insertion at the Beginning: A new node is created, its next pointer is set to the current head, and the head is updated to the new node.
  • Insertion at the End: A new node is added at the end of the list. This requires traversing to the last node.
  • Insertion in the Middle: A new node is inserted at a specific position by adjusting the pointers of the surrounding nodes.

Deletion Operation:
This involves removing a node from the linked list.
  • Deletion at the Beginning: The head is moved to the second node, and the first node is removed.
  • Deletion at the End: The last node is removed by traversing to the second-to-last node and setting its next pointer to NULL.
  • Deletion from the Middle: A specific node is removed by adjusting the pointer of the previous node to point to the next node.

Searching Operation:
This is the process of finding a specific node in the linked list. It involves starting from the head and checking the data of each node until the desired node is found.

Printing the List:
This operation involves printing all the nodes in order, starting from the head and following the next pointers until NULL is reached.

Reversing the List:
This process reverses the pointers of all nodes in the list, making the first node the last and the last node the first.