20 #define max(a,b) ((a) > (b) ? (a) : (b)) char * str
The name of this node or leaf.
Definition: tree.h:29
int isLeaf(Tree *t)
Check whether the tree is a leaf or not.
Definition: tree.c:44
Tree * createNode(int id, char *str, Tree *child)
Create a new node.
Definition: tree.c:29
Tree * LCA(Tree *root, int id1, int id2)
Find the lowest common ancestor We traverse from root to leaf. When we find a node matching at least ...
Definition: tree.c:99
Tree * createLeaf(int id, char *str)
Create a new leaf.
Definition: tree.c:20
Tree * addChild(Tree *node, Tree *child)
Add a child to a node.
Definition: tree.c:39
int height(Tree *t)
Get the height of a tree.
Definition: tree.c:61
Vector(struct Tree) children
All the children of this node (nothing means leaf)
int id
The unique identifier of this node or leaf.
Definition: tree.h:27
Contains the definition of the vectors (dynamic & generic arrays)
void freeTree(Tree *t)
Free the tree.
Definition: tree.c:133
int depth(Tree *root, int id)
Get the depth of a node in the tree.
Definition: tree.c:74
Defines the n-ary tree.
Definition: tree.h:25
int isNodeDepthSameOrSmaller(Tree *t, int node1, int node2)
Is node1 have same or smaller depth that node2?
Definition: tree.c:141