-
Notifications
You must be signed in to change notification settings - Fork 307
/
bitree.c
65 lines (52 loc) · 1.52 KB
/
bitree.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* struct */
typedef struct BiTreeNode_
{
char *data;
struct BiTreeNode_ *left;
struct BiTreeNode_ *right;
} BiTreeNode;
struct struct BiTree_
{
int size;
BiTreeNode *root;
} BiTree;
/* define */
#define BITREE_SIZE(tree) ((tree)->size)
#define BITREE_ROOT(tree) ((tree)->root)
#define BITREE_IS_EOB(node) (NULL == (node))
#define BITREE_IS_LEAF(node) (NULL == (node)->left && NULL == (node)->right)
#define BITREE_DATA(node) ((node)->data)
#define BITREE_LEFT(node) ((node)->left)
#define BITREE_RIGHT(node) ((node)->right)
/* interface */
void bitree_init(BiTree *tree);
void bitree_destory(BiTree *tree);
int bitree_insert_left(BiTree *tree, char *dest, const char *data);
int bitree_insert_right(BiTree *tree, char *dest, const char *data);
void bitree_remove_left(BiTree *tree, char *dest);
void bitree_remove_right(BiTree *tree, char *dest);
int bitree_merge(BiTree *merge, BiTree *left, BiTree *right, const char *data);
int bitree_search(BiTree *tree, char *search, BiTreeNode **node);
/* start */
void bitree_init(BiTree *tree)
{
tree->size = 0;
tree->root = NULL;
}
void bitree_destory(BiTree *tree)
{
}
int bitree_search(BiTree *tree, char *search, BiTreeNode *node)
{
//没有传入要搜寻的字符串,直接返回树根节点
if (NULL == search) {
*node = BITREE_ROOT(tree);
return 0;
}
}
int bitree_insert_left(BiTree *tree, char *dest, const char *data)
{
}