-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharbol_publico.cpp
More file actions
66 lines (64 loc) · 1.24 KB
/
arbol_publico.cpp
File metadata and controls
66 lines (64 loc) · 1.24 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
#include<iostream>
using namespace std;
class node{
public:
int id;
node* left;
node* right;
node(int, node*,node*);
int show_id();
node* show_left();
node* show_right();
};
node :: node(int _id, node* _left, node* _right){
id = _id;
right = _right;
left = _left;
}
int node::show_id(){
return id;
}
node* node::show_left(){
return left;
}
node* node::show_right(){
return right;
}
class tree{
public:
void driver_add_id(int new_id,node* root){
if(root == NULL){
node* n = new node(new_id,NULL,NULL);
root = n;
}
else{
if(new_id < root->id){
cout << "izquirda" << endl;
driver_add_id(new_id,root->left);
}
else if(new_id > root->id){
cout << "derecha ";
driver_add_id(new_id,root->right);
}
}
}
node* root;
tree(node*);
void add_id(int);
node* show_root();
};
tree :: tree(node* _root){
root = _root;
}
void tree::add_id(int new_id){
driver_add_id(new_id,root);
}
node* tree::show_root(){
return root;
}
int main(){
tree arbol(NULL);
arbol.add_id(10);
arbol.add_id(5);
arbol.add_id(15);
}