wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

The following C function takes a singly-linked list as input argument. It modified by 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.

typed of struct node
{
int value;
struct node * next;
} Node;
Node *mode_to_ front(Node *head)
{
Node *p, *q;
if((head == NULL)(head next == NULL))
return head;
q = NULL;
p = head;
while (pnext != NULL)
{
q = p;
p = p next;
}
______________________
return head;
}

Choose the correct alternative to replace the blank line.

A
head = p; p->next = q; q next = NULL;
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
q = NULL; p next = head; head=p;
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
q next = NULL; p next = head; head = p;
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
q next = NULL; head = p; p next = head;
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C q next = NULL; p next = head; head = p;
This is the program by moving last element to front of list and returns modified list.

When while (P next != NULL) execute then p pass to q and now p point to next. When "while" condition is false then we get q next = NULL;
p next = head; head = p; means next to q made null, and points p next is head and then make p as the head.

flag
Suggest Corrections
thumbs-up
0
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Differentiability in an Interval
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon