-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbintree.h
49 lines (39 loc) · 1.21 KB
/
bintree.h
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
#define TREE_OK (0)
#define TREE_FAIL (-1)
#define LEFT 1
#define RIGHT 0
#if defined(REDBLACK)
#define RBONLY(x) x
#else
#define RBONLY(x)
#endif
/*
* Basic node structure. The actual size of a node is unknown as
* the user will have appended data bytes on to the end of
* this structure. The BINTREE_STUFF macro is a convenient way
* to summarize the items the tree algorithm requires in the
* node. Its argument is the tag of the structure being defined.
*/
#define BINTREE_STUFF(x) struct x *link[2] \
RBONLY(;int red)
typedef struct sBnode
{
BINTREE_STUFF(sBnode);
} Bnode;
/* Control structure for a binary tree */
typedef int (*CompFunc) (void *node1, void *node2);
typedef int (*DoFunc) (void *node, int level);
typedef struct sBintree
{
Bnode *DummyHead;
CompFunc Compare;
int DuplicatesOk;
int NodeSize;
} Bintree;
/* Prototypes */
Bintree *NewBintree (Bnode *dummy, CompFunc cf, int dup_ok, int node_size);
Bnode *FindBintree(Bintree *t, Bnode *n);
int InsBintree (Bintree *t, Bnode *n);
Bnode *DelBintree (Bintree *t, Bnode *n);
int WalkBintree(Bintree *t, DoFunc df);
Bnode *InitBintreeNode(int size);