Salve a tutti. Ho il seguente problema in C: date due Liste L1 e L2 le voglio fondere in un unica lista L3 in maniera alternata ricorsivamente. ESEMPIO L1 = 2,3,4,5; L2=6,7; devo ottenere la nuova lista L3 cosi composta: 2,6,3,7,4,5. Il mio programma funziona solo se le due liste hanno lo stesso numero di elementi. qualcuno mi puo aiutare???
codice:
struct elemento *FUSIONE(struct elemento *L1,struct elemento *L2,
                         struct elemento *testa)
{
 if ((L1!=NULL)||(L2!=NULL))
   {
    testa=(struct elemento *)malloc(sizeof (struct elemento));
    if (L1!=NULL)
      {
       testa->inf=L1->inf;
       
      }
    if (L2!=NULL)
      { 
       testa->next=(struct elemento *)malloc(sizeof (struct elemento));
       testa->next->inf=L2->inf;
       testa->next->next=FUSIONE(L1->next,L2->next,testa->next->next);
      }
    else
      {
       testa->next=NULL;
       testa->next->next=FUSIONE(L1->next,NULL,testa->next);
      }   
    return testa;
    }
 else
   return NULL; 
}
Testa e il puntatore della nuova lista.