Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct el{
  5.  
  6. int info;
  7. struct el *next;
  8.  
  9. };
  10.  
  11. typedef struct el ElementoDiLista;
  12. typedef ElementoDiLista* ListaDiElementi;
  13.  
  14. void add_head(ListaDiElementi *lista,int v){
  15.  
  16. ElementoDiLista *el=malloc(sizeof(ElementoDiLista));
  17. el->info=v;
  18. el->next=*lista;
  19.  
  20. *lista=el;
  21.  
  22. }
  23.  
  24. void add_tail(ElementoDiLista **lista, int v){
  25.  
  26. ElementoDiLista *corr=*lista;
  27. ElementoDiLista *el=malloc(sizeof(ElementoDiLista));
  28. el->info=v;
  29. el->next=NULL;
  30.  
  31. if(*lista==NULL){
  32.  
  33. *lista=el;
  34.  
  35. }
  36. else{
  37. while(corr->next!=NULL){
  38.  
  39. corr=corr->next;
  40. }
  41.  
  42. corr->next=el;
  43. }
  44.  
  45.  
  46. }
  47.  
  48.  
  49. void modifica(ListaDiElementi lista,ListaDiElementi *aux){
  50.  
  51. if(lista!=NULL){
  52.  
  53. if(lista->info%2==0){
  54.  
  55. add_tail(&(*aux),-1);
  56.  
  57.  
  58. }
  59.  
  60. add_tail(&(*aux),lista->info);
  61.  
  62. lista=lista->next;
  63.  
  64. modifica(lista,&(*aux));
  65.  
  66. }
  67.  
  68. }
  69.  
  70. main(){
  71.  
  72. ListaDiElementi lista=NULL;
  73. ListaDiElementi aux=NULL;
  74.  
  75. int v;
  76.  
  77.  
  78. scanf("%d",&v);
  79.  
  80. while(v>=0){
  81.  
  82. add_head(&lista,v);
  83.  
  84. scanf("%d",&v);
  85. }
  86.  
  87. modifica(lista,&aux);
  88.  
  89.  
  90. if(aux!=NULL){
  91.  
  92. while(aux!=NULL){
  93.  
  94. printf("%d ",aux->info);
  95.  
  96. aux=aux->next;
  97.  
  98. printf("-> ");
  99.  
  100.  
  101. }
  102.  
  103.  
  104. printf("NULL");
  105.  
  106. }
  107. else{
  108.  
  109. printf("NULL");
  110.  
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement