Given a linked list and a key element, we have to delete the node from the linked list.
Explanation and example:
If a linked list is like : 1 → 2 → 3 → 4 → 5 → 6
Case I: (key is not head)
The key value is 4
After deleting that node the linked list is:1 → 2 → 3 → 5 → 6
Case II: (key is head)
The key value is 1
After deleting that node the linked list is: 2 → 3 → 5 → 6
Algorithm:
To solve the problem there are two conditions,
C++ implementation:
Output