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);
|
2022-03-28 17:52:16 +00:00
|
|
|
|
2021-02-01 22:06:37 +00:00
|
|
|
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));
|
2022-03-28 17:52:16 +00:00
|
|
|
|
2021-02-01 22:27:01 +00:00
|
|
|
void bintree_destroy(BinTree *tree);
|
2022-03-28 17:52:16 +00:00
|
|
|
|
2021-02-01 22:27:01 +00:00
|
|
|
int bintree_ins_left(BinTree *tree, BinTreeNode *node, void *data);
|
2022-03-28 17:52:16 +00:00
|
|
|
|
2021-02-01 22:27:01 +00:00
|
|
|
int bintree_ins_right(BinTree *tree, BinTreeNode *node, void *data);
|
2022-03-28 17:52:16 +00:00
|
|
|
|
2021-02-01 22:27:01 +00:00
|
|
|
void bintree_rem_left(BinTree *tree, BinTreeNode *node);
|
2022-03-28 17:52:16 +00:00
|
|
|
|
2021-02-01 22:27:01 +00:00
|
|
|
void bintree_rem_right(BinTree *tree, BinTreeNode *node);
|
2022-03-28 17:52:16 +00:00
|
|
|
|
2022-03-30 23:36:00 +00:00
|
|
|
//int bintree_merge(BinTree *merge, BinTree *left, BinTree *right, void *data);
|
2022-03-28 17:52:16 +00:00
|
|
|
|
2021-02-01 22:27:01 +00:00
|
|
|
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
|