-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
133 lines (93 loc) · 3.34 KB
/
main.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "inttree.h"
#include "tree.h"
int main(int argc, char *argv[]){
IntTree* root = new IntTree(12);
root->addAsLastSon(new IntTree(8));
root->getSon(0)->addAsLastSon(new IntTree(4));
root->getSon(0)->addAsLastSon(new IntTree(9));
root->addAsLastSon(new IntTree(23));
root->getSon(1)->addAsLastSon(new IntTree(17));
root->getSon(1)->addAsLastSon(new IntTree(15));
root->display("* ");
cout<<"Valeur de la racine "<<root->getData()<<endl;
cout<<"Nombres de fils de la racine "<<root->nbSons()<<endl;
try{
root->getSon(-3);
} catch(out_of_range e){
cout<<"Out of range: "<<e.what()<<endl;
}
try{
root->setSon(1, new IntTree(343));
root->setSon(3, new IntTree(34));
} catch(out_of_range e){
cout<<"Out of range: "<<e.what()<<endl;
}
try {
root->removeLastSon();
root->removeLastSon();
root->removeLastSon();
root->removeLastSon();
} catch(length_error e){
cout<<"Length error: "<<e.what()<<endl;
}
Tree<string>* chaines = new Tree<string>("Hello, world");
chaines->addAsLastSon(new Tree<string>("Comment"));
chaines->addAsLastSon(new Tree<string>("Qui es-tu?"));
try{
chaines->getSon(0)->addAsLastSon(new Tree<string>("Ca va?"));
} catch(out_of_range e){
cout<<"Out of range: "<<e.what()<<endl;
}
try{
chaines->addSon(1, new Tree<string>("!"));
} catch(out_of_range e){
cout<<"Out of range: "<<e.what()<<endl;
}
chaines->display("* ");
try{
try{
chaines->removeSon(2);
} catch(length_error e){
cout<<"Length error: "<<e.what()<<endl;
}
} catch(out_of_range e){
cout<<"Out of range: "<<e.what()<<endl;
}
chaines->display("* ");
cout<<endl<<endl<<endl;
chaines->invert_display("* ");
Tree<int>* root2 = new Tree<int>(12);
root2->addAsLastSon(new Tree<int>(8));
root2->getSon(0)->addAsLastSon(new Tree<int>(4));
root2->getSon(0)->addAsLastSon(new Tree<int>(9));
root2->addAsLastSon(new Tree<int>(23));
root2->getSon(1)->addAsLastSon(new Tree<int>(17));
root2->getSon(1)->addAsLastSon(new Tree<int>(15));
cout<<endl<<endl<<endl;
root2->display("* ");
root2->addSon(0, new Tree<int>(34));
root2->display("* ");
cout<<"_________________"<<endl;
root2->removeSon(2);
root2->display("* ");
cout<<"_________________"<<endl;
root2->invert_display("* ");
Tree<int>* root3 = new Tree<int>(1);
root3->addAsLastSon(new Tree<int>(2));
root3->addAsLastSon(new Tree<int>(3));
root3->addAsLastSon(new Tree<int>(4));
root3->getSon(0)->addAsLastSon(new Tree<int>(5));
root3->getSon(0)->addAsLastSon(new Tree<int>(6));
root3->getSon(0)->getSon(1)->addAsLastSon(new Tree<int>(8));
root3->getSon(2)->addAsLastSon(new Tree<int>(7));
root3->getSon(2)->getSon(0)->addAsLastSon(new Tree<int>(9));
root3->getSon(2)->getSon(0)->addAsLastSon(new Tree<int>(10));
root3->getSon(2)->getSon(0)->addAsLastSon(new Tree<int>(11));
root3->getSon(2)->getSon(0)->getSon(0)->addAsLastSon(new Tree<int>(12));
cout<<"_________________"<<endl;
root3->display("* ");
cout<<"_________________"<<endl;
root3->breadth_first_display("* ");
delete root3;
return 0;
}