GATE CS 2010 — Question 35

Multiple choice 2 marks Question 35 2010

Question 35

MCQ 2 marks · −0.66 Programming and Data Structures

The following C function takes a singly linked list as an 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.

Answers and explanations are free — they just need an account.

Where this question comes from

Source: GATE 2010 Computer Science and Engineering, Q35 (question number approximate)