#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int categoria;
int atributoOuDecisao;
struct node *prox;
struct node *lista;
} No;
No *criaArvore(void) {
No
*inicio
= malloc(sizeof(No
)); inicio->atributoOuDecisao = 0;
inicio->categoria = 99;
inicio->lista = NULL;
inicio->prox = NULL;
return inicio;
}
No *criaFilho(No *pai, int atributoDoPai, int categoriaDoFilho, int atributoOuDecisao) {
p1->atributoOuDecisao = atributoOuDecisao;
p1->categoria = categoriaDoFilho;
p1->lista = NULL;
p1->prox = NULL;
if (pai->lista == NULL) {
pai->lista = p1;
} else {
No *aux = pai->lista;
while (aux->prox != NULL) {
aux = aux->prox;
}
pai->prox = p1;
}
return p1;
}
int main() {
No *arv = criaArvore();
No *aux = criaFilho(arv, 1, 1, 3);
criaFilho(aux, 3, 0, 1);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnR5cGVkZWYgc3RydWN0IG5vZGUgewogICAgaW50IGNhdGVnb3JpYTsKICAgIGludCBhdHJpYnV0b091RGVjaXNhbzsKICAgIHN0cnVjdCBub2RlICpwcm94OwogICAgc3RydWN0IG5vZGUgKmxpc3RhOwp9IE5vOwoKTm8gKmNyaWFBcnZvcmUodm9pZCkgewogICAgTm8gKmluaWNpbyA9IG1hbGxvYyhzaXplb2YoTm8pKTsKICAgIGluaWNpby0+YXRyaWJ1dG9PdURlY2lzYW8gPSAwOwogICAgaW5pY2lvLT5jYXRlZ29yaWEgPSA5OTsKICAgIGluaWNpby0+bGlzdGEgPSBOVUxMOwogICAgaW5pY2lvLT5wcm94ID0gTlVMTDsKICAgIHJldHVybiBpbmljaW87Cn0KCk5vICpjcmlhRmlsaG8oTm8gKnBhaSwgaW50IGF0cmlidXRvRG9QYWksIGludCBjYXRlZ29yaWFEb0ZpbGhvLCBpbnQgYXRyaWJ1dG9PdURlY2lzYW8pIHsKICAgIE5vICpwMSA9IG1hbGxvYyhzaXplb2YoTm8pKTsKICAgIHAxLT5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