ProgrammingVery hard

In a 6-node list with values 10, 20, 30, 40, 50, 60, the standard slow and fast pointer method (slow moves one step, fast two steps, while fast and fast->next are non-NULL) stops with slow at which value?

  1. A. 30
  2. B. 50
  3. C. 60
  4. D. 40

Correct answer: D. 40

Fast starts at index 0 and moves two nodes per round, so the loop runs three rounds: slow goes to index 1, 2, 3, while fast goes to 2, 4, then past the end. Slow stops at index 3, which holds 40.

More C Programming questions

Exams that ask this topic