-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharbol_binario.cpp
More file actions
84 lines (82 loc) · 1.94 KB
/
arbol_binario.cpp
File metadata and controls
84 lines (82 loc) · 1.94 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
#include<iostream>
using namespace std;
class node{
private:
int id;
node* left_son;
node* right_son;
public:
node(int,node*,node*);
int mostrar_id();
node* mostrar_hijo_izquierdo();
node* mostrar_hijo_derecho();
};
node :: node(int _id, node* _left_son, node* _right_son){
id = _id;
left_son = _left_son;
right_son = _right_son;
}
int node ::mostrar_id(){
return id;
}
node* node:: mostrar_hijo_derecho(){
return right_son;
}
node* node:: mostrar_hijo_izquierdo(){
return left_son;
}
class tree{
private:
node* root;
void driver_add_id(int new_id,node* new_root){
if(new_root == nullptr){
node* n = new node(new_id,nullptr,nullptr);
cout << n << endl;
new_root = n;
cout << new_root << endl;
}
else{
if(new_id < new_root->mostrar_id()){
driver_add_id(new_id,new_root->mostrar_hijo_izquierdo());
}
else{
driver_add_id(new_id,new_root->mostrar_hijo_derecho());
}
}
}
public:
tree(node*);
void add_id(int);
int mostrar_id();
node* mostrar_hijo_izquierdo();
node* mostrar_hijo_derecho();
};
tree::tree(node* _root){
root = _root;
}
int tree ::mostrar_id(){
return root->mostrar_id();
}
node* tree:: mostrar_hijo_derecho(){
return root->mostrar_hijo_derecho();
}
node* tree:: mostrar_hijo_izquierdo(){
return root->mostrar_hijo_izquierdo();
}
void tree::add_id(int new_id){
driver_add_id(new_id,root);
}
int main(){
node raiz(10,nullptr,nullptr);
node* apuntador = &raiz;
tree root(apuntador);
root.add_id(6);
cout << root.mostrar_id() << endl;
node* puntero = root.mostrar_hijo_derecho();
node* puntero2 = root.mostrar_hijo_izquierdo();
node nodin = *puntero;
if(puntero == nullptr){
cout << " mocos" << endl;
}
cout << nodin.mostrar_id() << endl;
}