Question 7 of 1412 points

Question 7 · 12 points

Circular elimination

Each node represents one person, and the last node points back to the first.

typedef struct person {
    int id;
    struct person *next;
} person_t;

int eliminate_every_kth(person_t **head, int k);

Implement the function so that every k-th person is eliminated until only one person remains. Remove and free each eliminated node, update *head, and return the surviving person’s id.

State how you handle invalid inputs such as head == NULL, *head == NULL, or k <= 0.

Your response

Your answer

0 words