-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbst.h
46 lines (41 loc) · 1.12 KB
/
bst.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
/*
* bst.h - a simple binary search tree implementation in C
*
* Header file for bst.c.
*
*/
#ifndef BINARY_SEARCH_TREE
#define BINARY_SEARCH_TREE
/*
* A node in the binary search tree. Has pointers
* to its parent and both childs. Also contains
* a pointer to the string used as key and
* the data integer
*/
typedef struct BstNode
{
struct BstNode *parent;
struct BstNode *left;
struct BstNode *right;
char *key;
int data;
} BstNode;
/*
* A binary search tree. Contains a pointer
* to the root node of the tree
*/
typedef struct BstTree
{
BstNode *root;
} BstTree;
/* Function prototypes for binary search tree: */
struct BstNode* bst_newNode(char*, int);
struct BstTree* bst_newTree(void);
void bst_inorderTreeWalk(struct BstTree*, void(*) (BstNode*));
void bst_inorderTreeWalkFromNode(struct BstNode*, void(*) (BstNode*));
void bst_postorderTreeWalk(struct BstTree*, void(*) (BstNode*));
void bst_postorderTreeWalkFromNode(struct BstNode*, void(*) (BstNode*));
void bst_destroyNode(struct BstNode*);
void bst_destroyTree(struct BstTree*);
void bst_insertOrUpdate(struct BstTree*, struct BstNode*);
#endif