Consider the linked list initially having values $1, 2, 2, 8, 6, 2, 2,$ and let the head be the pointer to the first node of the linked list.
Which of the following options correctly represents the final linked list after the function call $\textsf{mystery(head, 2)}?$
typedef struct node {
int value;
struct node *next;
} Node;
Node* mystery(Node* head, int x) {
if (head == NULL)
return NULL;
if (head → value == x) {
Node* tmp = head → next;
free(head);
return tmp;
} else {
head → next = mystery(head → next, x);
return head;
}
}
- Final LinkedList will be $1, 2, 8, 6, 2, 2$
- Final LinkedList will be $1, 8, 6$
- Final LinkedList will be $1, 8, 6, 2, 2$
- None of the above