Arrays & Linked Lists

Your answer
Answer & solution
Answer: B (no official key was published)
1. p starts at the first node and q at the second. The temporary variable exchanges their value fields; no next pointer is modified.
2. p=q->next advances to the next pair’s first node, and q becomes its successor when it exists. Thus pairs (1,2), (3,4), (5,6) swap.
3. The final node 7 has no partner, so q becomes null and the loop stops. The sequence is 2,1,4,3,6,5,7, B.