ProgrammingHard

Reversing the list 1 -> 2 -> 3 -> 4 -> 5 in place with the usual three-pointer loop, what are head->v and head->next->v afterwards?

  1. A. 5 and 4
  2. B. 1 and 2
  3. C. 5 and 1
  4. D. 4 and 3

Correct answer: A. 5 and 4

After reversal the old tail 5 becomes the head and 4 follows it. The loop saves next before redirecting each pointer, so no node is lost.

More C Programming questions

Exams that ask this topic