-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary.h
More file actions
72 lines (65 loc) · 1.34 KB
/
binary.h
File metadata and controls
72 lines (65 loc) · 1.34 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
#include <iostream>
namespace bsoft{
template<class T> class Node{
private:
T value;
Node *left;
Node *right;
bool hasLeft, hasRight;
public:
Node(T value);
void remove(T value);
void insert(T value);
void display();
int search(T valu);
};
}
template<class T>
bsoft::Node<T>::Node(T value){
this->value = value;
this->hasLeft = false;
this->hasRight = false;
}
template<class T>
bsoft::Node<T>* getLowest(bsoft::Node<T>* node){
node->left;
}
template<class T>
void bsoft::Node<T>::remove(T value){
std::cout<<"I workout"<<std::endl;
}
template<class T>
int bsoft::Node<T>::search(T valu){
if( this->value == valu){
return this->value;
}else if(this->value > valu && this->hasLeft){
return this->left->search(valu);
}else if(this->hasRight){
return this->right->search(valu);
}
return NULL;
}
template<class T>
void bsoft::Node<T>::display(){
if(this->hasLeft){ this->left->display(); }
std::cout<<this->value<<" ";
if(this->hasRight){ this->right->display(); }
}
template<class T>
void bsoft::Node<T>::insert(T value){
if(this->value > value){
if(this->hasLeft){
this->left->insert(value);
}else{
this->left = new Node(value);
this->hasLeft = true;
}
}else{
if(this->hasRight){
this->right->insert(value);
}else{
this->right = new Node(value);
this->hasRight = true;
}
}
}