Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct el{
- int info;
- struct el *next;
- };
- typedef struct el ElementoDiLista;
- typedef ElementoDiLista* ListaDiElementi;
- void add_head(ListaDiElementi *lista,int v){
- ElementoDiLista *el=malloc(sizeof(ElementoDiLista));
- el->info=v;
- el->next=*lista;
- *lista=el;
- }
- void add_tail(ElementoDiLista **lista, int v){
- ElementoDiLista *corr=*lista;
- ElementoDiLista *el=malloc(sizeof(ElementoDiLista));
- el->info=v;
- el->next=NULL;
- if(*lista==NULL){
- *lista=el;
- }
- else{
- while(corr->next!=NULL){
- corr=corr->next;
- }
- corr->next=el;
- }
- }
- void modifica(ListaDiElementi lista,ListaDiElementi *aux){
- if(lista!=NULL){
- if(lista->info%2==0){
- add_tail(&(*aux),-1);
- }
- add_tail(&(*aux),lista->info);
- lista=lista->next;
- modifica(lista,&(*aux));
- }
- }
- main(){
- ListaDiElementi lista=NULL;
- ListaDiElementi aux=NULL;
- int v;
- scanf("%d",&v);
- while(v>=0){
- add_head(&lista,v);
- scanf("%d",&v);
- }
- modifica(lista,&aux);
- if(aux!=NULL){
- while(aux!=NULL){
- printf("%d ",aux->info);
- aux=aux->next;
- printf("-> ");
- }
- printf("NULL");
- }
- else{
- printf("NULL");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement