Pick the fix
The start pixel's colour already equals the new colour. What should a version that uses colour as the visited mark do?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Return straight away, because nothing would change
Right: without this check it keeps revisiting the same pixels.
When the old and new colours match, a repainted pixel still looks unvisited, so the early exit is required.
Why not the others?
- B Repaint the start pixel and continue. Every neighbour still matches, so the walk never ends.
- C Use a different new colour. The caller chose the colour; the function should handle this case.