• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

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

Consider the following C function takes a singly-linked list as input argument.
C
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

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments