Last active
January 2, 2016 18:59
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [... 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