BST.hpp
1.96 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
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
92
93
94
95
96
97
#ifndef BST_HPP
#define BST_HPP
#include "BSTNode.hpp"
#include "BSTIterator.hpp"
#include <utility> // for std::pair
template<typename Data>
class BST {
protected:
/** Pointer to the root of this BST, or nullptr if the BST is empty */
BSTNode<Data>* root;
/** Number of Data items stored in this BST. */
unsigned int isize;
public:
/** iterator is an aliased typename for BSTIterator<Data>. */
typedef BSTIterator<Data> iterator;
/** Default constructor.
Initialize an empty BST.
*/
BST() : root(nullptr), isize(0) {
}
/** Default destructor.
* It is virtual, to allow appropriate destruction of subclass objects.
* Delete every node in this BST.
*/ // TODO
virtual ~BST() {
}
/** Insert a Data item in the BST.
* Return a pair, with the pair's first member set to an
* iterator pointing to either the newly inserted element
* or to the equivalent element already in the set.
* The pair's second element is set to true
* if a new element was inserted or false if an
* equivalent element already existed.
*/ // TODO
virtual std::pair<iterator,bool> insert(const Data& item) {
}
/** Find a Data item in the BST.
* Return an iterator pointing to the item, or the end
* iterator if the item is not in the BST.
*/ // TODO
iterator find(const Data& item) const {
}
/** Return the number of items currently in the BST.
*/ // TODO
unsigned int size() const {
}
/** Remove all elements from this BST, and destroy them,
* leaving this BST with a size of 0.
*/ // TODO
void clear() {
}
/** Return true if the BST is empty, else false.
*/ // TODO
bool empty() const {
}
/** Return an iterator pointing to the first item in the BST.
*/ // TODO
iterator begin() const {
}
/** Return an iterator pointing past the last item in the BST.
*/
iterator end() const {
return typename BST<Data>::iterator(nullptr);
}
};
#endif //BST_HPP