-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18-binary_tree_uncle.c
More file actions
37 lines (33 loc) · 905 Bytes
/
18-binary_tree_uncle.c
File metadata and controls
37 lines (33 loc) · 905 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
#include "binary_trees.h"
/**
* binary_tree_uncle - finds the uncle of a node
* @node: a pointer to the node to find the uncle
*
* Return: pointer to the uncle node
* NULL if node is NULL
* NULL if the parent is NULL
* NULL if the node has no uncle
*/
binary_tree_t *binary_tree_uncle(binary_tree_t *node)
{
if (!node || !node->parent)
return (NULL);
return (binary_tree_sibling(node->parent));
}
/**
* binary_tree_sibling - finds the sibling of a node
* @node: pointer to the node to find the sibling
*
* Return: pointer to the sibling node
* NULL if node is NULL
* NULL if the parent is NULL
* NULL if the node has no siblings
*/
binary_tree_t *binary_tree_sibling(binary_tree_t *node)
{
if (!node || !node->parent)
return (NULL);
if (node == node->parent->left)
return (node->parent->right);
return (node->parent->left);
}