Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Rimuovere l'ultimo elemento dispari dalla lista*/
- #include <stdio.h>
- #include <stdlib.h>
- struct el{
- int info;
- struct el* next;
- };
- typedef struct el ElementoDiLista;
- typedef struct el * ListaDiElementi;
- void stampa(ListaDiElementi l){
- while(l->next!=NULL)
- {
- printf("%d\n", l->info);
- l=l->next;
- }
- }
- /*Rimuove l'ultimo elemento dispari della lista*/
- void rimuovi (ListaDiElementi *l){
- ListaDiElementi corr=*l, prec=NULL, save=NULL, prec_ultimo=NULL;
- int trovato=0;
- while(corr->next!=NULL){
- if (corr->info%2!=0){
- save=prec;
- prec_ultimo=corr->next;
- trovato=1;
- }
- prec=corr;
- corr=corr->next;
- }
- if (save==NULL && trovato==1){
- *l=(*l)->next;
- }
- else if (trovato==1 && save!=NULL){
- save->next=prec_ultimo;
- }
- }
- int main(){
- ListaDiElementi l=malloc(sizeof(ElementoDiLista));
- ListaDiElementi corr=l;
- int x=7,n=0;
- int i=0;
- while(i<10)
- {
- scanf("%d",&n);
- corr->info=n;
- corr->next=malloc(sizeof(ElementoDiLista));
- corr=corr->next;
- i++;
- }
- corr->next=NULL;
- rimuovi (&l);
- stampa(l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement