Singly Linked List
Singly Linked List
In a single linked list, the address of the first node is always stored in a
reference node known as "front" (Some times it is also known as "head").
Always next part (reference part) of the last node must be NULL.
Example
Insertion
In a single linked list, the insertion operation can be performed in three ways. They
are as follows...
1. Inserting At Beginning of the list
2. Inserting At End of the list
3. Inserting At Specific location in the list
www.vectorindia.org 1
Singly Linked List
www.vectorindia.org 2
Singly Linked List
www.vectorindia.org 3
Singly Linked List
Insertion not possible!!!' and terminate the function. Otherwise move the
temp to next node.
Step 7 - Finally, Set 'newNode → next = temp → next' and 'temp → next =
newNode'
Deletion
In a single linked list, the deletion operation can be performed in three ways. They
are as follows...
1. Deleting from Beginning of the list
2. Deleting from End of the list
3. Deleting a Specific Node
www.vectorindia.org 4
Singly Linked List
www.vectorindia.org 5
Singly Linked List
Step 6 - If it is FALSE. Then, set 'temp2 = temp1 ' and move temp1 to its
next node. Repeat the same until it reaches to the last node in the list. (until
temp1 → next == NULL)
Step 7 - Finally, Set temp2 → next = NULL and delete temp1.
www.vectorindia.org 6
Singly Linked List
Step 6 - If it is reached to the exact node which we want to delete, then check
whether list is having only one node or not
Step 7 - If list has only one node and that is the node to be deleted, then set
head = NULL and delete temp1 (free(temp1)).
Step 8 - If list contains multiple nodes, then check whether temp1 is the first
node in the list (temp1 == head).
Step 9 - If temp1 is the first node then move the head to the next node
(head = head → next) and delete temp1.
Step 10 - If temp1 is not first node then check whether it is last node in the
list (temp1 → next == NULL).
Step 11 - If temp1 is last node then set temp2 → next = NULL and delete
temp1 (free(temp1)).
Step 12 - If temp1 is not first node and not last node then set temp2 → next
= temp1 → next and delete temp1 (free(temp1)).
Note :
www.vectorindia.org 7