I'm trying to build a tree that gets a fully mathematic math expression [ex: ((a + b) + c)], but I think my insert function is wrong! Can someone give me a light?
typedef struct arvore {
char info;
struct arvore*esq;
struct arvore*dir;
}no;
no *cria(no*raiz, char el[], int i){
int j = i;
char s= el[j];
//printf("%s", el);
if(raiz == NULL){
raiz = (no*)malloc(sizeof(no));
(raiz)->dir = NULL;
(raiz)->esq = NULL;
}
if(s == '('){
j++;
s=el[j];
raiz->esq = cria(raiz->esq, el, j);
if(s == '+'){
(raiz)->info = s;
j++;
s=el[j];
raiz->dir = cria((raiz)->dir, el, j);
if(s==')'){
j++;
s=el[j];
//return raiz;
}
}
}else{
(raiz)->info=s;
j++;
s=el[j];
return raiz;
}
}
The intention is to make the tree have only letters and operators, and each node that has an operator in the info field will have 2 children with letters in the respective information fields!