The following C function takes a singly-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank.
typedef struct node
{
int value;
struct node *next;
} Node;
Node *move_to-front(Node *head)
{
Node *p, *q;
if ((head == NULL) || (head -> next == NULL))
return head;
q = NULL;
p = head;
while (p->next != NULL)
{
q=p;
p=p->next;
}
_______________
return head;
}
Choose the correct alternative to replace the blank line.
- $q=NULL; p \rightarrow next = head; head = p$;
- $q \rightarrow next = NULL; head = p; p \rightarrow next = head$;
- $head = p; p \rightarrow next =q; q \rightarrow next = NULL$;
- $q \rightarrow next = NULL; p \rightarrow next = head; head = p$;