Salve a tutti secondo voi questa ricorsione che ho scritto fa veramente la somma dei valori contenuti nelle foglie di un albero binario?
Il parametro k della funzione è la grandezza dell'albero (che il realtà non so a che mi può servire, ma nell'esercizio dice esplicitamente che deve essere data in ingresso)
Codice PHP:
typedef int itemtype;
typedef struct nodo *ptree;
typedef struct nodo{
itemtype item;
ptree left, right;
}nodedescriptor;
int somma(ptree t, int k){
if(t == null) return 0;
return t->item + somma(left(t), k) + somma(right(t), k);
}