Salve,vi posto un esercizio svolto dove secondo me c'è un errore,al posto dell'and dovrebbe esserci un or.Che ne dite?
Scrivere una funzione booleana che, dato un albero binario di stringhe,
restituisce 1 se esiste almeno un nodo che ha due figli e
questi figli contengono lo stesso valore, 0 altrimenti.
codice:#include <stdlib.h> typedef struct nodo *ptree; struct nodo { char *item; ptree left, right; }; int ex2(ptree t){ if (t==NULL) return 0; if (t->left!=NULL){ if (t->right==NULL) return ex2(t->left); else {if (strcmp(t->left->item,t->right->item)==0) return 1; else return ex2(t->left) && ex2(t->right);} } else return ex2(t->right); }

Rispondi quotando