-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.h
More file actions
62 lines (41 loc) · 1.22 KB
/
tree.h
File metadata and controls
62 lines (41 loc) · 1.22 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
59
60
61
62
#ifndef _TREE_H_
#define _TREE_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define ROOT_NODE_C -2
#define INTERNAL_NODE_C -3
struct _TreeNode{
int c;
int occ;
struct _TreeNode *left;
struct _TreeNode *right;
struct _TreeNode *parent;
};
typedef struct _TreeNode *TreeNode;
struct _Tree{
TreeNode root;
};
typedef struct _Tree *Tree;
// create the treenode with c and occ only, leave connection to be done later
TreeNode TreeNodeCreate(int c, int occ);
TreeNode TreeNodeDelete(TreeNode);
Tree TreeCreate(TreeNode root);
Tree TreeDestroy(Tree);
bool IsTreeNodeValid(TreeNode);
bool IsRootNode(TreeNode);
bool IsInternalNode(TreeNode);
bool IsLeafNode(TreeNode);
bool IsOccSmaller(TreeNode trn1, TreeNode trn2);
bool IsLeftChild(TreeNode child, TreeNode parent);
int GetC(TreeNode);
int GetOcc(TreeNode);
void SetOcc(TreeNode trn, int occ);
int SumTwoOcc(TreeNode trn1, TreeNode trn2);
void ConnectAsLeftChild(TreeNode child, TreeNode parent);
void ConnectAsRightChild(TreeNode child, TreeNode parent);
void ConnectAsChild(TreeNode child, TreeNode parent, bool isRightChild);
void ResetInternalNodeToRootNode(TreeNode);
int TreeNodeGetDepth(TreeNode trn);
void TreeShow(Tree);
#endif