-
Notifications
You must be signed in to change notification settings - Fork 1
/
binaryTree.h
46 lines (31 loc) · 1.08 KB
/
binaryTree.h
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
/* My Binary Tree Specification */
#ifndef BINARY_TREE_HEADER
#define BINARY_TREE_HEADER
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct s_btree MyTree;
/* ENUM FOR TREE ORDER TRAVERSALS */
typedef enum { PREORDER = 0, INORDER = 1, POSTORDER = 2 } order_t;
/* CREATE A NEW TREE OBJECT */
MyTree* newTree(void);
/* RETURNS THE AMOUNT OF NODES IN THE TREE */
int treeSize(MyTree* tree);
/* ADD NODE TO THE TREE */
void addNode(MyTree* tree, int elem);
/* REMOVE ALL INSTANCES OF ELEM FROM THE TREE */
void removeNode(MyTree* tree, int elem);
/* CHECK IF ELEM EXISTS IN TREE */
bool isNode(MyTree* tree, int elem);
/* DETERMINES IF TREE IS EMPTY */
bool isEmpty(MyTree* tree);
/* ORDER FUNCTIONS
* Returned array must be freed by caller.
*/
int* orderTraversal(MyTree* tree, order_t order);
/* FREE ALL SPACE USED BY TREE */
void freeTree(MyTree* tree);
/* PRINT TREE */
void printTree(MyTree* tree, order_t order);
void visualizeTree(MyTree* tree, unsigned int depth);
#endif /* BINARY_TREE_HEADER */