0
I need to implement a code that calculates the height of a tree Trie in the C language.
To struct
of knot is the following:
struct trie_cel {
char tipo; // 'I': interno / 'P': palavra
struct trie_cel *filho[TAMANHO_ALFABETO]; // Utilizar a funcao CHAR_TO_INDEX para obter o no filho de cada letra.
};
typedef struct trie_cel no;
I’m trying to calculate the height of a tree Trie with recursion, this is my function:
int altura(no* r) {
if(r == NULL) return -1;
if(!r) return 0;
int alt = 0;
int alturaM = 0;
no** i = r->filho;
no** fim = i + (sizeof(r->filho) / sizeof(no *));
while(i != fim){
alt = altura(r->filho[i])+1;
if(alt > alturaM){
alturaM = alt;
}
}
return alturaM;
}
However the following error is being presented and I am not being able to locate it.
trie.cpp: In function ‘int altura(no*)’: trie.cpp:146:32: error: invalid types ‘trie_cel* [27][no** {aka trie_cel**}]’ for array subscript alt = altura(r->filho[i])+1; ^