mame83
11-11-2010, 11:23
Salve ragazzi sono nuovo su questo forum. ho questo problema: devo creare una lista con una funzione ricorsiva, la funzione che ho creato mi resituisce sempre il puntatore della testa a null e non so perchè. Spero che qualcuno mi aiuti.:mc:
struct elemento*crea_lista(struct elemento*testa,struct elemento*app, int n)
{
if (n==0)
return testa;
else
{
if (testa==NULL)
{
printf("testa = NULL \n");
testa=(struct elemento*)malloc(sizeof(struct elemento));
testa->inf=3;
app=testa;
app->next=crea_lista(testa,app,n-1);
}
else
{
printf("testa diverso da null \n");
app=(struct elemento*)malloc(sizeof(struct elemento));
app->inf=4;
app->next=crea_lista(testa,app,n-1);
}
}
}
struct elemento*crea_lista(struct elemento*testa,struct elemento*app, int n)
{
if (n==0)
return testa;
else
{
if (testa==NULL)
{
printf("testa = NULL \n");
testa=(struct elemento*)malloc(sizeof(struct elemento));
testa->inf=3;
app=testa;
app->next=crea_lista(testa,app,n-1);
}
else
{
printf("testa diverso da null \n");
app=(struct elemento*)malloc(sizeof(struct elemento));
app->inf=4;
app->next=crea_lista(testa,app,n-1);
}
}
}