Practice ยท 3 of 4
The Second Level
Demonstrate two-level indirection with a "cursor" API. The type is
provided in the boilerplate:
``c
typedef struct { const int *cur, *end; } IntCursor;
`
Implement:
`c
/* initializes the cursor over [a, a+n); NULL args leave it empty
(cur == end == NULL). */
void cursor_init(IntCursor *c, const int *a, size_t n);
/* copies the next value into *out and advances; returns 1, or 0 when exhausted
(leaving *out untouched). */
int cursor_next(IntCursor *c, int *out);
/* rewinds to the start of the original range (no-op if empty). */
void cursor_reset(IntCursor *c, const int *a, size_t n);
``
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Two-Level Indirection Gym