-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_definition.cc
More file actions
59 lines (53 loc) · 1.18 KB
/
Copy pathtree_definition.cc
File metadata and controls
59 lines (53 loc) · 1.18 KB
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
#include "tree_definition.h"
#include <cstddef>
#include <assert.h>
TreeNode_s::TreeNode_s( DATA_type theData)
: data(theData)
, parent(NULL)
, lchild(NULL)
, rchild(NULL)
#ifdef RB_TREE
, color(true)
#endif
{
}
void TreeNode_s::ConstructTree( TreeNode_p_t &theTree, TreeNode_p_t parentTree, char* &theKeyWds)
{
if(!theKeyWds)
return;
if(*theKeyWds == '#')
theTree = NULL;
else
{
theTree = new TreeNode_s(*theKeyWds);
theTree->parent = parentTree;
assert(theTree);
++theKeyWds;
if(!theKeyWds || *theKeyWds == '\0')
return;
ConstructTree(theTree->lchild, theTree, theKeyWds);
++theKeyWds;
if(!theKeyWds|| *theKeyWds == '\0')
return;
ConstructTree(theTree->rchild, theTree, theKeyWds);
}
}
void TREE_constuct( TreeNode_p_t &theTree, TreeNode_p_t parentTree, char* &theKeyWds)
{
return TreeNode_s::ConstructTree(theTree, parentTree, theKeyWds);
}
void TREE_destroy(TreeNode_p_t *root)
{
if(*root == NULL)
return;
TREE_destroy(&((*root)->lchild));
TREE_destroy(&((*root)->rchild));
delete *root;
*root = NULL;
}
void TREE_get_node_value( TreeNode_p_t &theTree, const void** data )
{
if(!theTree)
return ;
*data = &theTree->data;
}