2021-02-01 22:06:37 +00:00
|
|
|
#ifndef LIBFLINT_BINARY_TREE_H
|
|
|
|
#define LIBFLINT_BINARY_TREE_H
|
|
|
|
|
2021-02-01 22:27:01 +00:00
|
|
|
typedef struct BinTreeNode {
|
2021-02-01 22:06:37 +00:00
|
|
|
void *data;
|
|
|
|
struct BinTreeNode *left;
|
|
|
|
struct BinTreeNode *right;
|
2021-02-01 22:27:01 +00:00
|
|
|
} BinTreeNode;
|
2021-02-01 22:06:37 +00:00
|
|
|
|
2021-02-01 22:27:01 +00:00
|
|
|
typedef struct {
|
2021-02-01 22:06:37 +00:00
|
|
|
int size;
|
|
|
|
|
|
|
|
int (*compare)(const void *a, const void *b);
|
|
|
|
void (*destroy)(void *data);
|
|
|
|
|
|
|
|
struct BinTreeNode *root;
|
2021-02-01 22:27:01 +00:00
|
|
|
} BinTree;
|
2021-02-01 22:06:37 +00:00
|
|
|
|
2021-02-01 22:27:01 +00:00
|
|
|
void bintree_init(BinTree *tree, void (*destroy)(void *data));
|
|
|
|
void bintree_destroy(BinTree *tree);
|
|
|
|
int bintree_ins_left(BinTree *tree, BinTreeNode *node, void *data);
|
|
|
|
int bintree_ins_right(BinTree *tree, BinTreeNode *node, void *data);
|
|
|
|
void bintree_rem_left(BinTree *tree, BinTreeNode *node);
|
|
|
|
void bintree_rem_right(BinTree *tree, BinTreeNode *node);
|
|
|
|
int bintree_merge(BinTree *merge, BinTree *left, BinTree *right, void *data);
|
|
|
|
void bintree_debug_print(BinTree *tree);
|
2021-02-01 22:06:37 +00:00
|
|
|
|
|
|
|
#define bintree_is_eob(node) ((node) == NULL)
|
|
|
|
#define bintree_is_leaf(node) ((node)->left == NULL && (node)->right == NULL)
|
|
|
|
|
|
|
|
#endif
|