Maybe fold this into a `for (int i = 0; cur != NULL; ++i, cur = cur->next)` statement?