-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbst.h
More file actions
37 lines (28 loc) · 1.02 KB
/
Copy pathbst.h
File metadata and controls
37 lines (28 loc) · 1.02 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
#ifndef BST_H
#define BST_H
struct BST_Node{
struct BST_Node *left_child;
struct BST_Node *right_child;
int key;
void *data;
};
// Returns BST_Node of the node who key matches the search_key
// Returns NULL if search_key is not found in the BST
struct BST_Node *bst_search( struct BST_Node *root, int search_key );
// Adds the given <key, data> pair to the BST
// Returns BST_SUCCESS upon success, BST_DUP_KEY if duplicate key is being sent
// Note that the ADDRESS of the root (instead of root) should be sent as first paraemter
// For example:
// BST_Node *root;
// int ststus = bst_add_node (&root, somekey, somedata);
int bst_add_node( struct BST_Node **root, int key, void *data );
// Prints the keys of the BST
void bst_print( struct BST_Node *root );
// Releases the entire BST by recursively calling free()
void bst_free( struct BST_Node *root );
// Frees not only the nodes but also the data in the nodes
void bst_destroy( struct BST_Node *root );
#define BST_SUCCESS 0
#define BST_DUP_KEY 1
#define BST_NULL 2
#endif