We have discussed Linked List Introduction and Linked List Insertion in previous posts on a singly linked list.
Let us formulate the problem statement to understand the deletion process. Given a ‘key’, delete the first occurrence of this key in the linked list.
To delete a node from the linked list, we need to do the following steps.
1) Find the previous node of the node to be deleted.
2) Change the next of the previous node.
3) Free memory for the node to be deleted.
Since every node of the linked list is dynamically allocated using malloc() in C, we need to call free() for freeing memory allocated for the node to be deleted.
Created Linked List: 2 3 1 7 Linked List after Deletion of 1: 2 3 7
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Create new linked list from two given linked list with greater element at each node
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Swap Kth node from beginning with Kth node from end in a Linked List
- Swap Kth node from beginning with Kth node from end in a Doubly Linked List
- Insert a node in Linked List before a given node
- Merge a linked list into another linked list at alternate positions
- Check if a linked list is Circular Linked List
- Convert singly linked list into circular linked list
- Difference between Singly linked list and Doubly linked list
- Convert Singly Linked List to XOR Linked List
- Linked List | Set 2 (Inserting a node)
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Create a linked list from two linked lists by choosing max element at each position
- Construct a Doubly linked linked list from 2D Matrix
- Given only a pointer/reference to a node to be deleted in a singly linked list, how do you delete it?
- Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
- Delete a node in a Doubly Linked List
- Delete a given node in Linked List under given constraints
- Point to next higher value node in a linked list with an arbitrary pointer