Scritto da
Non Autenticato
il 2010-05-05 17:57:00.0 alle 2010-05-05 17:57:00.0
Qualcuno può aiutarmi con le strutture
ricorsive? Non riesco proprio a capirle.Mi potete descrivere questo programma? Grazie mille!
#include <stdio.h>
#include <stdlib.h>
struct nodo *crealista();
void printlista(struct nodo *p);
struct nodo
{
int dato;
struct nodo *next;
};
main()
{
struct nodo *start;
start=crealista();
printlista(start);
printf ("\n\n\n");
system("pause");
return 0;
}
struct nodo *crealista()
{
struct nodo *p,*start,*last;
int i,n,x;
start=NULL;
printf ("quanti nodi ha la lista?");
scanf ("%d",&n);
printf ("\n\n\ndigitare elementi:");
for (i=0;i<n;i++)
{
scanf ("%d",&x);
p=(struct nodo *) malloc(sizeof(struct nodo));
if (i==0)
start=p;
else
last->next=p;
p->dato=x;
p->next=NULL;
last=p;
}
return (start);
}
void printlista(struct nodo *p)
{
printf ("\n\n\n");
while (p!=NULL)
{
printf ("%d --->",p->dato);
p=p->next;
}
printf ("NULL\n");
return;
}