Created
February 7, 2018 08:59
-
-
Save aziis98/265c25bc8be022ae363b72b645b4e941 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| typedef struct elemento{ | |
| int info; | |
| struct elemento *next; | |
| }Elemento; | |
| typedef Elemento *Lista; | |
| void metti(Lista *lista){ | |
| int n; | |
| scanf("%d", &n); | |
| if(n!=0){ | |
| *lista=malloc(sizeof(Elemento)); | |
| (*lista)->info=n; | |
| (*lista)->next=NULL; | |
| metti(&((*lista)->next)); | |
| } | |
| } | |
| void print_lista(Lista lista) { | |
| if(lista!=NULL){ | |
| printf("%d -> ", lista->info); | |
| print_lista(lista->next); | |
| } | |
| else printf("NULL\n"); | |
| } | |
| void funct1(Lista lista) { | |
| while(lista!=NULL){ | |
| if(lista->info % 2==0) { | |
| lista->info=lista->info*10; | |
| } | |
| lista=lista->next; | |
| } | |
| } | |
| void funct2(Lista lista){ | |
| while(lista!=NULL){ | |
| if(lista->info % 3 == 0) { | |
| printf("next: %d\n", lista->next->info); | |
| lista->info=(lista->info+lista->next->info)/2; | |
| lista->next=lista->next->next; | |
| } | |
| lista=lista->next; | |
| } | |
| } | |
| int main(void) { | |
| Lista lista = NULL; | |
| metti(&lista); | |
| print_lista(lista); | |
| funct2(lista); | |
| print_lista(lista); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment