diff options
| author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-06 21:15:06 -0400 | 
|---|---|---|
| committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-08 11:04:22 -0400 | 
| commit | 005c0514d3caf2b76bb563136ef6496716f43ebb (patch) | |
| tree | 4d2b62d92fa29e9ffbbcac2660642ef4c6eb4ea4 /collections/map | |
| parent | d165f723621fcbed677d879e188a1a162812f667 (diff) | |
Add height helper function for maps
Diffstat (limited to 'collections/map')
| -rw-r--r-- | collections/map/map.c | 14 | 
1 files changed, 14 insertions, 0 deletions
| 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;  { | 
