-
Notifications
You must be signed in to change notification settings - Fork 0
/
bst.h
50 lines (44 loc) · 1.35 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
47
48
49
50
#ifndef BST_H
# define BST_H
typedef struct Node {
void *data;
struct Node *left;
struct Node *right;
int ht;
} Node_t;
typedef struct BST {
Node_t *root;
int (*predicate)();
int size_of_type;
} Set;
typedef struct Iterator {
Node_t *ptr;
Node_t *root;
int (*predicate)();
} Iterator_t;
/* tree(set) interface */
Set *init_set(int (*predicate)(), int size_of_type);
void disp(Iterator_t *begin, Iterator_t *end, void (*printer)());
void insert(Set *tree, void *data);
void erase(Set *tree, void *data);
void clear(Set *tree);
int size(Set *tree);
void merge(Set *set1, Set *set2);
/* Iterator interface */
void init_iterator(Iterator_t *iter, Set *tree);
Iterator_t *find(Set *tree, void *data, int (*comparator)());
Iterator_t *begin(Set *tree);
Iterator_t *end(Set *tree);
Iterator_t *rbegin(Set *tree);
Iterator_t *rend(Set *tree);
void next(Iterator_t *iter);
void prev(Iterator_t *iter);
int is_not_null(Iterator_t *iter);
Iterator_t *lower_bound(Iterator_t *begin, Iterator_t *end, void *data, int (*comparator)());
Iterator_t *upper_bound(Iterator_t *begin, Iterator_t *end, void *data, int (*comparator)());
void *get_data(Iterator_t *it);
#endif
/* after making things generic user should provide 3 things */
/* 1. His own comparator taking void* params */
/* 2. His own Predicate taking void* params */
/* 3. His own printer taking void* params */