daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. struct listaNodi {
  5.    int val;
  6.    struct listaNodi *next;
  7. };
  8. typedef struct listaNodi ListaNodi;
  9. typedef struct ListaNodi *List;
  10.  
  11.  
  12. void InvertiLista(List *);
  13. void AddValore(List *, int);
  14. void Stampa(List *);
  15.  
  16.  
  17. int main()
  18. {
  19.  int n;
  20.  List head=NULL;
  21.  printf("Inserisci un numero : ");
  22.  while((scanf("%d",&n))>0)
  23.  {
  24.      AddValore(&head,n);
  25.      Stampa(&head);
  26.      printf("Inserisci un numero : \n");
  27.  }
  28.  InvertiLista(&head);
  29.  return 0;
  30. }
  31.  
  32.  
  33.  
  34. void AddValore(List *s,int n)
  35. {
  36.  List succ;
  37.  succ = malloc(sizeof(ListaNodi));
  38.  succ->val = n;
  39.  succ-> next = *s;
  40.  *s = succ;
  41. }
  42.  
  43.  
  44. void Stampa(List *s)
  45. {
  46.  List stp;
  47.  stp= *s;
  48.  if(stp == NULL)
  49.  {
  50.     printf("Lista vuota");
  51.  }
  52.  else
  53.  {
  54.   printf("La lista e' : ");
  55.   while(stp !=NULL)
  56.   {
  57.     printf("%d --> ",stp->val);
  58.     stp = stp->next;
  59.   }
  60.   printf("NONE \n \n");
  61.  }
  62. }  
  63.    
  64.  
  65.  
  66.  
  67. void InvertiLista(List *s)
  68. {
  69.  List new;
  70.  new=*s;
  71.  if(new==NULL)
  72.  {
  73.     printf("Lista vuota");
  74.  }
  75.  else
  76.  {
  77.    printf("La lista e' : ");
  78.    while(new != NULL)
  79.    {
  80.        printf("%d", new->val);
  81.        new=new->next;
  82.    }
  83.    printf("NONE \n \n");
  84.   }
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top