From 005c0514d3caf2b76bb563136ef6496716f43ebb Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 6 Jul 2020 21:15:06 -0400 Subject: Add height helper function for maps --- collections/map/map.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'collections/map/map.c') diff --git a/collections/map/map.c b/collections/map/map.c index a476a97..f61e8ef 100644 --- a/collections/map/map.c +++ b/collections/map/map.c @@ -12,6 +12,20 @@ struct map_node { struct map_node *left, *right, *parent; }; +int map_height(root) +map *root; +{ + int l, r; + + if (!root || !root->key) + return 0; + + l = map_height(root->left); + r = map_height(root->right); + + return 1 + ( l > r ? l : r); +} + map* map_new(cmp) cmp_func cmp; { -- cgit v1.1