28 #define TREE_RIGHT(node) (NULL!=(node)?(node)->right:NULL)
29 #define TREE_LEFT(node) (NULL!=(node)?(node)->left:NULL)
30 #define TREE_PARENT(node) (NULL!=(node)?(node)->parent:NULL)
32 #define TREE_CHILD(node) \
33 (NULL==TREE_RIGHT((node))?TREE_LEFT((node)):TREE_RIGHT((node)))
35 #define TREE_RIGHT_LEFT(node) \
36 (NULL!=TREE_RIGHT((node))?TREE_LEFT(TREE_RIGHT((node))):NULL)
38 #define TREE_LEFT_RIGHT(node) \
39 (NULL!=TREE_LEFT((node))?TREE_RIGHT(TREE_LEFT((node))):NULL)
41 #define TREE_SIBLING(node) \
42 (NULL!=TREE_PARENT((node))? \
43 ((node)==TREE_PARENT((node))->left? \
44 TREE_PARENT((node))->right: \
45 TREE_PARENT((node))->left): \
48 #define TREE_GRANDPARENT(node) \
49 (NULL!=TREE_PARENT((node))?TREE_PARENT((node))->parent:NULL)
51 #define TREE_UNCLE(node) \
52 (NULL!=TREE_GRANDPARENT((node))? \
53 (TREE_PARENT((node))==TREE_GRANDPARENT((node))->left? \
54 TREE_GRANDPARENT((node))->right: \
55 TREE_GRANDPARENT((node))->left): \
58 #define TREE_ROTATE_LEFT(root, node) \
60 if (NULL != TREE_RIGHT_LEFT((node))) { \
61 TREE_RIGHT_LEFT((node))->parent = (node); \
63 TREE_RIGHT((node))->left = (node); \
64 if (NULL != TREE_PARENT((node))) { \
65 if (TREE_PARENT((node))->left==(node)) { \
66 TREE_PARENT((node))->left = (node)->right; \
68 TREE_PARENT((node))->right = (node)->right; \
71 *(root) = (node)->right; \
73 (node)->right = TREE_RIGHT_LEFT((node)); \
74 (node)->parent = (node)->right; \
75 TREE_RIGHT((node))->parent = (node)->parent; \
78 #define TREE_ROTATE_RIGHT(root, node) \
80 if (NULL != TREE_LEFT_RIGHT((node))) { \
81 TREE_LEFT_RIGHT((node))->parent = (node); \
83 TREE_LEFT((node))->right = (node); \
84 if (NULL != TREE_PARENT((node))) { \
85 if (TREE_PARENT((node))->left==(node)) { \
86 TREE_PARENT((node))->left = (node)->left; \
88 TREE_PARENT((node))->right = (node)->left; \
91 *(root) = (node)->left; \
93 TREE_LEFT((node))->parent = (node)->parent; \
94 (node)->left = TREE_LEFT_RIGHT((node)); \
95 (node)->parent = (node)->right; \
98 #define TREE_REPLACE_NODE(root, node1, node2) \
100 if (NULL != TREE_PARENT((node1))) { \
101 if ((node1) == TREE_PARENT((node1))->left) { \
102 TREE_PARENT((node1))->left = (node2); \
104 TREE_PARENT((node1))->right = (node2); \
109 if (NULL != (node2)) { \
110 (node2)->parent = (node1)->parent; \
127 typedef int (*
TreeComp)(
const void *,
const void *);
void * treeInsert(Tree *, const void *, TreeComp)
int(* TreeComp)(const void *, const void *)
void(* TreeAction)(const void *, const int)
void * treeFind(Tree, const void *, TreeComp)
void * treeDelete(Tree *, const void *, TreeComp)
void treeWalk(Tree, TreeAction)
void treeDestroy(Tree *, TreeAction)