data-structures · intermediate · ~15 min

Reverse a linked list

Three-pointer in-place reversal.

Challenge

Given the same node_t definition, implement node_t *reverse(node_t *head) returning the new head of the reversed list. Reverse in place — do not allocate new nodes.

Starter code

node_t *reverse(node_t *head) {
    /* TODO */
    return head;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.