-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBST.cpp
More file actions
35 lines (32 loc) · 739 Bytes
/
BST.cpp
File metadata and controls
35 lines (32 loc) · 739 Bytes
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
#include "BST.h"
bool BST::contains(const T& obj) {
if (value == obj) {
return true;
}
if (left && value > obj) {
return left->(contains(obj));
}
if (right && value < obj) {
return right->contains(obj));
}
return false;
}
const T& BST::get(const T& obj) const {
return set(obj);
}
T& BST::set(const T& obj) {
try {
if (value == obj) {
return obj;
}
if (left && value > obj) {
return left->(get(obj));
}
if (right && value < obj) {
return right->get(obj));
}
}
catch (...) {
throw "Null reference exception: Search tree does not contain specified value.\n";
}
}