Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- struct listaNodi {
- int val;
- struct listaNodi *next;
- };
- typedef struct listaNodi ListaNodi;
- typedef struct ListaNodi *List;
- void InvertiLista(List *);
- void AddValore(List *, int);
- void Stampa(List *);
- int main()
- {
- int n;
- List head=NULL;
- printf("Inserisci un numero : ");
- while((scanf("%d",&n))>0)
- {
- AddValore(&head,n);
- Stampa(&head);
- printf("Inserisci un numero : \n");
- }
- InvertiLista(&head);
- return 0;
- }
- void AddValore(List *s,int n)
- {
- List succ;
- succ = malloc(sizeof(ListaNodi));
- succ->val = n;
- succ-> next = *s;
- *s = succ;
- }
- void Stampa(List *s)
- {
- List stp;
- stp= *s;
- if(stp == NULL)
- {
- printf("Lista vuota");
- }
- else
- {
- printf("La lista e' : ");
- while(stp !=NULL)
- {
- printf("%d --> ",stp->val);
- stp = stp->next;
- }
- printf("NONE \n \n");
- }
- }
- void InvertiLista(List *s)
- {
- List new;
- new=*s;
- if(new==NULL)
- {
- printf("Lista vuota");
- }
- else
- {
- printf("La lista e' : ");
- while(new != NULL)
- {
- printf("%d", new->val);
- new=new->next;
- }
- printf("NONE \n \n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement