A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

Discussion Forum

Que. The following C function takes a simply-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. Choose the correct alternative to replace the blank line.
typedef struct node
  int value;
  struct node *next;
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;
a. q = NULL; p->next = head; head = p;
b. q->next = NULL; head = p; p->next = head;
c. head = p; p->next = q; q->next = NULL;
d. q->next = NULL; p->next = head; head = p;
Answer:q->next = NULL; p->next = head; head = p;
Confused About the Answer? Ask for Details Here
Know Explanation? Add it Here

Similar Questions: