-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15-binary_tree_is_full.c
More file actions
54 lines (42 loc) · 1003 Bytes
/
15-binary_tree_is_full.c
File metadata and controls
54 lines (42 loc) · 1003 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "binary_trees.h"
/**
* binary_tree_is_leaf - checks if a node is a leaf
* @node: pointer to the node to check
*
* Return: 1 if node is a leaf, otherwise 0
*/
int binary_tree_is_leaf(const binary_tree_t *node)
{
int leaf = 0;
if (node && !(node->left) && !(node->right))
leaf = 1;
return (leaf);
}
/**
* binary_tree_is_parent_full - checks if a node is a parent
* @node: pointer to the node to check
* Return: 1 if node is a parent, otherwise 0
*
*/
int binary_tree_is_parent_full(const binary_tree_t *node)
{
int parent = 0;
if (node && node->left && node->right)
parent = 1;
return (parent);
}
/**
* binary_tree_is_full - checks if a binary tree is full
* @tree: tree root
*
* Return: 1 if tree is full, 0 otherwise
*/
int binary_tree_is_full(const binary_tree_t *tree)
{
if (binary_tree_is_leaf(tree))
return (1);
if (binary_tree_is_parent_full(tree))
return (binary_tree_is_full(tree->left) &&
binary_tree_is_full(tree->right));
return (0);
}