Question 40 The following C function takes a single-linked list of integers as a parameter...
Cisco technical mcq question, verified with a worked answer. Free to practise - no sign-up.
The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1, 2, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution?
struct node {
int value;
struct node *next;
};
void rearrange(struct node *list)
{
struct node *p, *q;
int temp;
if ((!list) || !list->next)
return;
p = list;
q = list->next;
while(q)
{
temp = p->value;
p->value = q->value;
q->value = temp;
p = q->next;
q = p?p->next:0;
}
}
Show answer & explanation
Answer: A. A) 1,2,3,4,5
Accurate technical and quantitative evaluation based on foundational principles.
Step-by-step Derivation:
Step 1: Formulate problem conditions.
Step 2: Apply logical deduction.
Step 3: Conclude correct option.