#include <stdlib.h>
#include <stdio.h>
typedef int tree_info;
typedef struct no_arvbin * arvbin;
struct no_arvbin {
arvbin esq;
tree_info dado;
arvbin dir;
};
void preordem(arvbin t);
/**Ex 1**/
void preordemprintafolha(arvbin t);
/**Ex 2**/
void encontraMaior(arvbin t, int *maior);
void criaRaiz (arvbin t);
int main() {
arvbin a
= (arvbin
) malloc(sizeof(arvbin
)); arvbin b
= (arvbin
) malloc(sizeof(arvbin
)); arvbin c
= (arvbin
) malloc(sizeof(arvbin
)); arvbin d
= (arvbin
) malloc(sizeof(arvbin
));
criaRaiz(a);
criaRaiz(b);
criaRaiz(c);
criaRaiz(d);
a->dado = 6;
b->dado = 3;
c->dado = 2;
d->dado = 4;
a->esq = b;
a->dir = c;
b->esq = d;
int maior = -1;
encontraMaior(a, &maior);
return 0;
}
void criaRaiz(arvbin t) {
t->esq = NULL;
t->dir = NULL;
}
void preordem(arvbin t) {
if (t != NULL) {
preordem(t->esq);
preordem(t->dir);
}
}
void preordemprintafolha(arvbin t) {
if (t != NULL) {
if (t->dir == NULL && t->esq == NULL) {
}
preordemprintafolha(t->esq);
preordemprintafolha(t->dir);
}
}
void encontraMaior(arvbin t, int *maior) {
/*system("pause\n");
printf("%d ", *maior);
printf(" %p\n", maior);
system("pause");*/
if (t != NULL) {
if (*maior < t->dado) {
*maior = t->dado;
//printf("%p %p", maior, &t->dado);
}
encontraMaior(t->esq, maior);
encontraMaior(t->dir, maior);
}
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KCnR5cGVkZWYgaW50IHRyZWVfaW5mbzsKdHlwZWRlZiBzdHJ1Y3Qgbm9fYXJ2YmluICogYXJ2YmluOwpzdHJ1Y3Qgbm9fYXJ2YmluIHsKICAgIGFydmJpbiBlc3E7CiAgICB0cmVlX2luZm8gZGFkbzsKICAgIGFydmJpbiBkaXI7Cn07Cgp2b2lkIHByZW9yZGVtKGFydmJpbiB0KTsKCi8qKkV4IDEqKi8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mRlbXByaW50YWZvbGhhKGFydmJpbiB0KSB7CiAgICBpZiAodCAhPSBOVUxMKSB7CiAgICAgICAgaWYgKHQtPmRpciA9PSBOVUxMICYmIHQtPmVzcSA9PSBOVUxMKSB7CiAgICAgICAgICAgIHByaW50ZigiJWRcbiIsIHQtPmRhZG8pOwogICAgICAgIH0KICAgICAgICBwcmVvcmRlbXByaW50YWZvbGhhKHQtPmVzcSk7CiAgICAgICAgcHJlb3JkZW1wcmludGFmb2xoYSh0LT5kaXIpOwogICAgfQp9Cgp2b2lkIGVuY29udHJhTWFpb3IoYXJ2YmluIHQsIGludCAqbWFpb3IpIHsKICAgIC8qc3lzdGVtKCJwYXVzZVxuIik7CiAgICBwcmludGYoIiVkICIsICptYWlvcik7CiAgICBwcmludGYoIiAlcFxuIiwgbWFpb3IpOwogICAgc3lzdGVtKCJwYXVzZSIpOyovCiAgICBpZiAodCAhPSBOVUxMKSB7CiAgICAgICAgaWYgKCptYWlvciA8IHQtPmRhZG8pIHsKICAgICAgICAgICAgKm1haW9yID0gdC0+ZGFkbzsKICAgICAgICAgICAgLy9wcmludGYoIiVwICVwIiwgbWFpb3IsICZ0LT5kYWRvKTsKICAgICAgICB9CgogICAgICAgIGVuY29udHJhTWFpb3IodC0+ZXNxLCBtYWlvcik7CiAgICAgICAgZW5jb250cmFNYWlvcih0LT5kaXIsIG1haW9yKTsKICAgIH0KfQ==