data-structures · beginner · ~15 min
Accumulate while traversing a list.
With the same node_t, implement long list_sum(node_t *head) returning the sum of all values (0 for NULL).
typedef struct node { int v; struct node *next; } node_t;
long list_sum(node_t *head) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.