Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2188 views
1
/*
2
* Main developer: Nico Van Cleemput
3
* In collaboration with: Craig Larson
4
*
5
* Copyright (C) 2013 Ghent University.
6
* Licensed under the GNU GPL, read the file LICENSE.txt for details.
7
*/
8
9
#ifndef BINTREES_H
10
#define BINTREES_H
11
12
#include "limits.h"
13
14
typedef int boolean;
15
#define TRUE 1
16
#define FALSE 0
17
18
typedef struct node {
19
struct node *left;
20
struct node *right;
21
22
int type; //i.e., number of children
23
int depth;
24
25
int pos;
26
27
int contentLabel[2];
28
} NODE;
29
30
typedef struct tree {
31
struct node *root;
32
33
struct node *unusedStack[MAX_NODES_USED - 1]; //-1 because root is never unused
34
int unusedStackSize;
35
36
struct node *nodesAtDepth[MAX_TREE_DEPTH+1][MAX_TREE_LEVEL_WIDTH];
37
int levelWidth[MAX_TREE_DEPTH+1];
38
int depth;
39
40
int unaryCount;
41
int binaryCount;
42
} TREE;
43
44
45
//------ Node operations -------
46
47
void addChildToNode(NODE *parent, NODE *child);
48
49
NODE *removeChildFromNode(NODE *parent);
50
51
void getOrderedNodes(NODE *node, NODE **orderedNodes, int *currentPosition);
52
53
//------ Tree operations -------
54
55
void initTree(TREE *tree);
56
57
void copyTree(TREE *tree, TREE *copy);
58
59
void freeTree(TREE *tree);
60
61
void addChildToNodeInTree(TREE *tree, NODE *parent);
62
63
void removeChildFromNodeInTree(TREE *tree, NODE *parent);
64
65
#endif /* BINTREES_H */
66
67
68