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?
- A. 30
- B. 50
- C. 60
- 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
- Which operation removes the k-th node (1-based) from a singly linked list in one pass with a pointer to the previous node, and handles…
- Which realloc pattern does not leak memory or lose the original block if the reallocation fails?
- A dynamic array doubles its capacity whenever it is full. Pushing N = 10^6 values costs about how many element copies in total?
- A function returns a pointer to a node created with malloc inside it. Which description is correct?
- Which statement about calloc(n, size) is guaranteed by the C standard?
- A program calls free(p) and then reads p->v in the next line. What is the correct description?