Qualcuno mi spiega come funziona questa semplice funzione e come si inizializza un albero binario nel main, cioč come si inseriscono gli elementi.
Grazie
Codice HTML:
#include <stdio.h>
#include <stdlib.h>
struct tree
{
int dato;
struct tree *sx;
struct tree *dx;
};
typedef struct tree tree;
int Ricerca(tree *t, int k)
{
//PRE LA FUNZIONE PRENDE IN INGRESSO UN ALBERO BINARIO t DI INTERI E UN......
//INTERO K DA CERCARE NEI NODI DELL'ALBERO
//POST LA FUNZIONE RESTITUISCE 1 SE K E' CONTENUTO IN ALMENO UN NODO,.........
//0 ALTRIMENTI. SE L'ALBERO E' VUOTO LA FUNZIONE RESTITUISCE 0
if(Is_Empty(t)==1){return 0;}
return t->dato == k
|| ricerca(t->sx, k);
|| ricerca(t->dx, k);}