Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- typedef struct nodo *lista;
- typedef struct nodo{
- int val;
- lista next;
- } nodo;
- lista insCoda(lista L,int val)
- {
- nodo *n,*tmp=L;
- n=malloc(sizeof(nodo));
- if(!n)
- {
- printf("MEMORIA ESAURITA!");
- return L;
- }
- n->val=val;
- n->next=NULL;
- while(tmp->next!=NULL) tmp=tmp->next;
- tmp->next=n;
- return L;
- }
- lista leggiLista(lista L)
- {
- int n,val;
- printf("\nQuanti valori vuoi inserire?");
- scanf("%d",&n);
- while(n--)
- {
- printf("\nInserisci il valore: ");
- scanf("%d",&val);
- if(!L)
- { L=malloc(sizeof(nodo));
- if(!L) return NULL;
- L->val=val;
- L->next=NULL;
- }
- else L=insCoda(L,val);
- }
- return L;
- }
- void stampaLista(lista L)
- {
- while(L)
- {
- printf("\n%d",L->val);
- L=L->next;
- }
- }
- int main(void)
- {
- lista L=NULL;
- L=leggiLista(L);
- stampaLista(L);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement