data-structures · beginner · ~15 min
Traverse a singly-linked list.
With typedef struct node { int v; struct node *next; } node_t;, implement int list_length(node_t *head) returning the number of nodes (0 for NULL).
typedef struct node { int v; struct node *next; } node_t;
int list_length(node_t *head) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.