Junior — Senior
Removing a specific element from a singly linked list, having access only to it
livecode
Task condition
Given a singly linked list: 4 → 1 → 3. It is only possible to access the node that contains the value 1. You need to delete this node without having a reference to the previous node (with value 4), so that the resulting list is 4 → 3.
struct ListNode {
int data;
ListNode* nxt;
};
// only a pointer ListNode* target is available, where target->data == 1
void deleteNode(ListNode* target) {
// implement
}