-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path1195.cpp
70 lines (60 loc) · 1.08 KB
/
1195.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
#include <iostream>
using namespace std;
struct No {
int info;
struct No *esq;
struct No *dir;
};
typedef struct No *Arvore;
void insere (Arvore& a, int c) {
if (a == NULL) {
a = new No;
a->info = c;
a->dir = NULL;
a->esq = NULL;
}
else if (c > a->info)
insere (a->dir, c);
else
insere (a->esq, c);
}
void preor (Arvore& a) {
if (a!=NULL) {
cout << " " << a->info;
preor (a->esq);
preor (a->dir);
}
}
void inor (Arvore& a) {
if (a!=NULL) {
inor (a->esq);
cout << " " << a->info;
inor (a->dir);
}
}
void posor (Arvore& a) {
if (a!=NULL) {
posor (a->esq);
posor (a->dir);
cout << " " << a->info;
}
}
int main () {
int n, qtd, val = 0;
cin >> n;
Arvore arv = NULL;
for(int j=0; j<n; j++){
arv = NULL;
cin >> qtd;
for(int i = 0; i < qtd; i++){
cin >> val;
insere(arv, val);
}
cout << "Case " << j + 1<< ":";
cout << "\nPre.:"; preor(arv);
cout << "\nIn..:"; inor(arv);
cout << "\nPost:"; posor(arv);
cout << endl << endl;
}
return 0;
}