Skip to content
Related Articles

Related Articles

Improve Article

GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 35

  • Last Updated : 26 Dec, 2019

Consider the following C function takes a singly-linked list as input argument.




typedef struct node {
  int value;
  struct node * next;
}
Node;
  
Node * modify_list(Node * head) {
  
    Node * p, * q;
    if ((head == NULL || (head-> next == NULL)) 
    return head; 
      
    q = NULL; 
    p = head;
      while (p-> next-> next != NULL) {
        q = p;
        p = p -> next;
      }
      q -> next = p -> next; 
      p -> next = head; 
      head = p;
        
      return head;
    }

It modifies the list
(A) by moving the last element to the front of the list and returns the modified list.
(B) by moving the second last element to the front of the list and returns the modified list.
(C) by moving the first element to the second last of the list and returns the modified list.
(D) by moving the first element to the last of the list and returns the modified list.


Answer: (B)

Explanation: Function modify_list(Node * head) modifies the list by moving the second last element to the front of the list and returns the modified list.

Option (B) is correct.

Quiz of this Question

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :