Skip to content

Instantly share code, notes, and snippets.

@alexwebr
Last active January 2, 2016 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexwebr/8347140 to your computer and use it in GitHub Desktop.
Save alexwebr/8347140 to your computer and use it in GitHub Desktop.
Recursively frees a singly-linked tree structure (each node has a child, a first sibling, or both)
// [... snip ...]
void free_tree(tree_t *p)
{
if (p->sibling != NULL) {
free_tree(p->sibling);
p->sibling = NULL;
}
if (p->child != NULL) {
free_tree(p->child);
p->child = NULL;
}
free(p);
}
// [... snip ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment