-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
astree.c
39 lines (32 loc) · 764 Bytes
/
astree.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
#include "astree.h"
#include <assert.h>
#include <stdlib.h>
void ASTreeAttachBinaryBranch(ASTreeNode* root, ASTreeNode* leftNode, ASTreeNode* rightNode)
{
assert(root != NULL);
root->left = leftNode;
root->right = rightNode;
}
void ASTreeNodeSetType(ASTreeNode* node, NodeType nodetype)
{
assert(node != NULL);
node->type = nodetype;
}
void ASTreeNodeSetData(ASTreeNode* node, char* data)
{
assert(node != NULL);
if(data != NULL) {
node->szData = data;
node->type |= NODE_DATA;
}
}
void ASTreeNodeDelete(ASTreeNode* node)
{
if (node == NULL)
return;
if (node->type & NODE_DATA)
free(node->szData);
ASTreeNodeDelete(node->left);
ASTreeNodeDelete(node->right);
free(node);
}