BST min/max implementation.
This commit is contained in:
parent
da0f81a9f7
commit
5428552cc8
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue