-
Notifications
You must be signed in to change notification settings - Fork 0
/
bst.h
executable file
·91 lines (71 loc) · 2.1 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* A definition for a binary search tree implementation.
*/
#ifndef __BST_H
#define __BST_H
/*
* Structure used to represent a binary search tree.
*/
struct bst;
/*
* Creates a new, empty binary search tree and returns a pointer to it.
*/
struct bst* bst_create();
/*
* Free the memory associated with a binary search tree.
*
* Params:
* bst - the binary search tree to be destroyed
*/
void bst_free(struct bst* bst);
/*
* Returns 1 if the given binary search tree is empty or 0 otherwise.
*
* Params:
* bst - the binary search tree whose emptiness is to be checked
*/
int bst_isempty(struct bst* bst);
/*
* Inserts a given value into an existing binary search tree.
*
* Params:
* val - the value to be inserted into the tree
* bst - the binary search tree into which to insert val
*/
void bst_insert(int val, struct bst* bst);
/*
* Removes a given value from an existing binary search tree. If the
* specified value is not contained in the specified tree, the tree is not
* modified.
*
* Params:
* val - the value to be removed from the tree
* bst - the binary search tree from which to remove val
*/
void bst_remove(int val, struct bst* bst);
/*
* Determines whether a binary search tree contains a given value.
*
* Params:
* val - the value to be found in the tree
* bst - the binary search tree in which to search for val
*
* Return:
* Returns 1 if bst contains val or 0 otherwise.
*/
int bst_contains(int val, struct bst* bst);
/*****************************************************************************
*
* Below are the functions and structures you'll implement in this assignment.
*
*****************************************************************************/
struct bst_iterator;
//int bst_count(struct bst_node* root);
int bst_size(struct bst* bst);
int bst_height(struct bst* bst);
int bst_path_sum(int sum, struct bst* bst);
struct bst_iterator* bst_iterator_create(struct bst* bst);
void bst_iterator_free(struct bst_iterator* iter);
int bst_iterator_has_next(struct bst_iterator* iter);
int bst_iterator_next(struct bst_iterator* iter);
#endif