1
0
Fork 0

BST min/max implementation.

This commit is contained in:
Wael Karram 2023-09-27 15:20:31 +03:00
parent da0f81a9f7
commit 5428552cc8
Signed by: wael
GPG Key ID: 3B356038CCB10808
2 changed files with 32 additions and 0 deletions

View File

@ -265,3 +265,31 @@ static inline void **sorted_array_from_binary_search_tree(tree_node_t *root, siz
/* Success. */
return array;
}
/* This function finds the tree's minimum. */
static inline tree_node_t* find_minimum_binary_search_tree(const tree_node_t* const root, int (*comparison_function)(const void*, const void*)) {
/* Sanity check. */
assert(root && comparison_function);
/* Local variables. */
tree_node_t *node = root;
while (node->left)
node = node->left;
return node;
}
/* This function finds the tree's maximum. */
static inline tree_node_t* find_maximum_binary_search_tree(const tree_node_t* const root, int (*comparison_function)(const void*, const void*)) {
/* Sanity check. */
assert(root && comparison_function);
/* Local variables. */
tree_node_t *node = root;
while (node->right)
node = node->right;
return node;
}

View File

@ -65,4 +65,8 @@ static inline size_t find_binary_search_tree_depth(const tree_node_t* const root
static inline void fill_array_binary_search_tree(tree_node_t *root, void **array, size_t *index, const size_t length);
/* This function creates a sorted array, from a binary search tree. */
static inline void **sorted_array_from_binary_search_tree(tree_node_t *root, size_t *length, int *resize_status);
/* This function finds the tree's minimum. */
static inline tree_node_t* find_minimum_binary_search_tree(const tree_node_t* const root, int (*comparison_function)(const void*, const void*));
/* This function finds the tree's maximum. */
static inline tree_node_t* find_maximum_binary_search_tree(const tree_node_t* const root, int (*comparison_function)(const void*, const void*));
#endif /* BINARY_SEARCH_TREE_H */