Practice ยท 2 of 2
Free a Graph Exactly Once
The boilerplate declares a tiny DAG of named nodes:
``c
typedef struct GNode {
char name;
struct GNode **kids; /* array of borrowed pointers, kids_len long */
size_t kids_len;
} GNode;
`
kids and its pointers are **owned by the node**; a node may be a child
of several parents (shared, borrowed from the parents' view). Implement:
`c
/* frees every distinct node reachable from root exactly once, then the
kids arrays, then returns how many nodes were freed */
size_t graph_free(GNode *root);
``
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Modeling & Ownership Gym