1
0
Fork 0
C_lib/docs/trees/binary_tree/binary_tree.h.ms

45 lines
2.1 KiB
Plaintext

.TL
binary_tree.h
.AU
Wael Karram
.AB no
Documentation for binary_tree.h
.AE
.DA
.LP
This header defines a binary tree, with the prepoccessor variable BINARY_TREE_H used as an include guard.
.br
Includes the struct
.UL tree_node_t \0which
has the fields
.I "left" ,\0
.I "right" \0and
.I "data" ,
the former of which are other node pointers, and the latter is a void pointer.
.LP
This header defines a special "max" macro, which takes two variables (a and b), checks that they have maching types, and returns the maximal value between them.
.LP
This header defines the following functions:
.br
tree_node_t* initialize_tree_node(): This function initializes an empty tree node, returning the pointer thereof on success and NULL on failure.
.br
tree_node_t* initialize_tree_node_store(void *data): This function initializes an empty tree node, returning the pointer thereof on success and NULL on failure - stores the given data into the node too.
.br
int link_tree_node_right(tree_node_t *parent, tree_node_t *child): This function links the child node to the right of its parent, will haLPily overwrite linked nodes!
.br
int link_tree_node_left(tree_node_t *parent, tree_node_t *child): This function links the child node to the left of its parent, will haLPily overwrite linked nodes!
.br
void free_tree(tree_node_t *root): This function frees a tree from the given node onwards (including all children thereof but not parentally), will not free stored data.
.br
void free_tree_data(tree_node_t *root, void (*free_function)(const void*)): This function frees a tree from the given node onwards (including all children thereof but not parentally), will also free stored data - if free_function is not NULL, it'll be used to free said data, otherwise will use stdlib's free().
.br
int insert_into_tree(tree_node_t *root, tree_node_t *to_insert, int (*comparison_function)(const void*, const void*)): This function attempts to automatically insert a node into a given tree (if any are NULL, will return an error), if comparison_function is NULL - will use standard < comparison instead.
.br
size_t find_tree_depth(tree_node_t *root): Finds the tree's depth at the given root.