-
Notifications
You must be signed in to change notification settings - Fork 0
/
btree_level_count.c
executable file
·29 lines (26 loc) · 1.24 KB
/
btree_level_count.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree_level_count.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <akharrou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/21 21:06:11 by akharrou #+# #+# */
/* Updated: 2019/03/04 13:17:20 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Includes/btree.h"
int btree_level_count(t_btree *root)
{
int left_count;
int right_count;
if (!root)
return (0);
left_count = 0;
right_count = 0;
if (root->left)
left_count = btree_level_count(root->left);
if (root->right)
right_count = btree_level_count(root->right);
return ((left_count > right_count) ? left_count + 1 : right_count + 1);
}