ho fatto questa funzione che cerca un nodo in un albero:
(controllo se l'elemento che cerco è nella radice. se non è cosi, se il nodo ha figli, chiamo ricorsivamente la funzione sul primo figlio, e poi ricorsivamente dovrebbe controllare gli altri)
codice:
struct node *cerca(struct node *root,struct node *elemento){
printf("nodo in esame: %s\n",root->name);
if (strcmp(root->name,elemento->name) == 0) { // controlla radice
printf("trovato\n");
return root;
} else {
if (root->children == NULL) return NULL;
iterator i = get_iterator(root->children);
while (has_next(i)) {
node temp = (node)next(i);
return cerca(temp,elemento);
}
return NULL;
}
}
pero non mi funziona la chiamta ricorsiva?? dove sbaglio?
le strutture node, list e iterator sono le seguenti:
codice:
struct NodoLista {
void *value;
struct NodoLista *next;
};
typedef struct NodoLista *list;
struct iterator {
struct NodoLista *pt;
};
typedef struct iterator *iterator;
struct node {
char *name;
list children;
node_type type;
list attributes;
};
typedef struct node *node;
ps:non posso cambiare le strutture