Ciao per motivi di tempo non ho letto tutto il tuo codice, mi sono solo soffermato sulla funzione inserimento dove pero non vedo l allocazione dinamica della memoria per un nuovo nodo....Void Inserimento(ABR T,tree z)
// Costruisce un albero binario di ricerca
{
//Puntatore al padre
tree Y=NULL;
tree X=T->root;
//tree X=T;
while (X!=NULL)
{
Y=X;
if ( z->key < X->key)
X=X->sinistro;
else
X=X->destro;
}
z->genitore=Y;
if (Y==NULL)
T->root=z;
else
if (z->key < Y->key)
Y->sinistro=z;
else
Y->destro=z;
z->sinistro=NULL;
z->destro=NULL;
}
Ti posto parzialmente quello su cui sto lavorando io, bada che cosi come è l albero sarà creato in maniera sbilanciata. In ogni caso spero che la traccia ti serva un po...Codice PHP:void insertTree(tree ** Ptr,char * buffer) // Inserimento nell albero, funzione ricorsiva
{
/* Caso base */
if((*Ptr)==NULL)
{
CreateNode(Ptr);
(*Ptr)->Comando=(char *)calloc(strlen(buffer)+1,sizeof(char));
strcpy((*Ptr)->Comando,buffer);
return;
}
/* Comando>buffer --> vado a sinistra*/
if(strcmp((*Ptr)->Comando,buffer)>0)
{
insertTree(&((*Ptr)->left),buffer);
return;
}
/* Comando<buffer --> vado a destra*/
else
{
insertTree(&((*Ptr)->right),buffer);
return;
}
} /* FINE insertTree */
/* Crea un nodo */
void CreateNode(tree ** dp)
{
(*dp)=(tree*)malloc(sizeof(tree));
(*dp)->left=NULL;
(*dp)->right=NULL;
} /* FINE CreateNode*/
![]()
![]()

Rispondi quotando