#include <stdio.h>
#include <stdlib.h>
typedef struct no {
int info;
struct no *esq;
struct no *dir;
} Node;
Node *insere(Node *arv, int valor) {
if (arv == NULL) {
arv->info = valor;
arv->esq = NULL;
arv->dir = NULL;
// arv = p;
return arv;
} else if (valor > arv->info) {
arv->dir = insere(arv->dir, valor);
return arv->dir;
} else {
arv->esq = insere(arv->esq, valor);
return arv->esq;
}
}
void imprime (Node *arv) {
if (arv != NULL) {
imprime(arv->esq);
imprime(arv->dir);
}
}
int main (void) {
Node
*arv
= malloc(sizeof(Node
)); arv->info = 1;
arv->dir = NULL;
arv->esq = NULL;
insere(arv, 2);
insere(arv, 3);
imprime(arv);
}
//https://pt.stackoverflow.com/q/190689/101
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnR5cGVkZWYgc3RydWN0IG5vIHsKICAgIGludCBpbmZvOwogICAgc3RydWN0IG5vICplc3E7CiAgICBzdHJ1Y3Qgbm8gKmRpcjsKfSBOb2RlOwoKTm9kZSAqaW5zZXJlKE5vZGUgKmFydiwgaW50IHZhbG9yKSB7CiAgICBpZiAoYXJ2ID09IE5VTEwpIHsKICAgICAgICBhcnYgPSBtYWxsb2Moc2l6ZW9mKE5vZGUpKTsKICAgICAgICBhcnYtPmluZm8gPSB2YWxvcjsKICAgICAgICBhcnYtPmVzcSA9IE5VTEw7CiAgICAgICAgYXJ2LT5kaXIgPSBOVUxMOwovLyAgICAgICAgYXJ2ID0gcDsKICAgICAgICByZXR1cm4gYXJ2OwogICAgfSBlbHNlIGlmICh2YWxvciA+IGFydi0+aW5mbykgewogICAgICAgIGFydi0+ZGlyID0gaW5zZXJlKGFydi0+ZGlyLCB2YWxvcik7CiAgICAgICAgcmV0dXJuIGFydi0+ZGlyOwogICAgfSBlbHNlIHsKICAgICAgICBhcnYtPmVzcSA9IGluc2VyZShhcnYtPmVzcSwgdmFsb3IpOwogICAgICAgIHJldHVybiBhcnYtPmVzcTsKICAgIH0KfQoKdm9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