diff options
Diffstat (limited to 'collections/map/map.c')
-rw-r--r-- | collections/map/map.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/collections/map/map.c b/collections/map/map.c index 712a895..beb8f7f 100644 --- a/collections/map/map.c +++ b/collections/map/map.c @@ -34,3 +34,47 @@ map *root; return map_size(root->left) + map_size(root->right) + 1; } + +void map_clear(root) +map *root; +{ + map *l, *r; + + l = root->left; + r = root->right; + + if (!root) + return; + + if (root->parent) { + free(root->key); + root->key = NULL; + + free(root->val); + root->val = NULL; + + root->parent = NULL; + + free(root); + } + + map_clear(l); + map_clear(r); +} + +void map_free(root) +map *root; +{ + if (!root) + return; + + root->key = NULL; + + map_free(root->left); + root->left = NULL; + + map_free(root->right); + root->right = NULL; + + free(root); +} |