C/C++ Arena

Step 5 of 6

Reverse a linked list

A famous interview question. Walk the list once and flip every next pointer to point backwards. You'll need three pointers: prev, cur, and next.

Your turn: write struct Node *reverse(struct Node *head) that returns the new head.

Previous: Free the whole list Next: A stack on an array