0
The error is found in else
of the method criarFilho
, I was able to locate it but I can not find solution for it.
The debug Dev-C++ does not point out anything.
#include <stdio.h>
#include <stdlib.h>
// #include "decisor.h"
typedef struct node {
int categoria;
int atributoOuDecisao;
struct node *prox;
struct node *lista;
} No;
No *criaArvore(void){
No *inicio = (No*)malloc(sizeof(No)); //Aloca memória para filho.
inicio->atributoOuDecisao = 0;
inicio->categoria = 99;
inicio->lista = NULL; //Inicializa Variaveis
inicio->prox = NULL;
return inicio; //Retorna Raiz
}
No *criaFilho (No *pai, int atributoDoPai, int categoriaDoFilho, int atributoOuDecisao){
No *p1 = (No*)malloc(sizeof(No)); //Cria Nó Filho
p1->atributoOuDecisao = atributoOuDecisao;
p1->categoria = categoriaDoFilho;
p1->lista = NULL;
p1->prox = NULL;
if (pai->lista = NULL) { //Testa se sublista é vazia, se sim então inicializa sublista com Filho.
pai->lista = p1;
}
else { //Se pai possui sublista, percorre sublista até o fim com auxiliar e posiciona Filho na ultima posição.
No *aux;
aux = pai->lista;
while (aux->prox != NULL){
aux = aux->prox;
}
aux->prox = p1;
}
return p1; //Retorna ponteiro para nó Filho
}
int main () {
No *aux, *aux2, *arv;
int *v;
arv=criaArvore();
aux=criaFilho(arv, 1, 1, 3);
criaFilho(aux, 3, 0, 1);
return 0;
}
Again, thank you very much. Recommends some IDE in particular?
– Marcos Pinheiro Moura
@Marcospinheiromoura again read the [tour] to understand how the site works. Visual Studio is the most used in Windows. If you prefer to use the GCC gives in VS too, but it is not common, there is a lot of option. There are those who like Code::Blocks, others prefer other things. There is a lot of offer of good things. That is, basically this is the only bad thing. I can’t understand why so many people choose to use a software with problems, that if search or show easy
– Maniero
@Marcospinheiromoura you can accept in the other too.
– Maniero