-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
function to find the uncle of a node in a tree
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "binary_trees.h" | ||
|
||
/** | ||
* binary_tree_uncle - Finds the uncle of a node | ||
* in a binary tree. | ||
* @node: A pointer to the node to find the uncle of. | ||
* | ||
* Return: If node is NULL or has no uncle, NULL. | ||
* Otherwise, a pointer to the uncle node. | ||
*/ | ||
binary_tree_t *binary_tree_uncle(binary_tree_t *node) | ||
{ | ||
if (node == NULL || | ||
node->parent == NULL || | ||
node->parent->parent == NULL) | ||
return (NULL); | ||
if (node->parent->parent->left == node->parent) | ||
return (node->parent->parent->right); | ||
return (node->parent->parent->left); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters