Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Sposta l'ultima occorrenza del valore X all'inizio della 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;
- }
- }
- void sposta (ListaDiElementi *l, int x){
- ListaDiElementi corr=*l, prec=NULL, save=NULL;
- if (*l!=NULL){
- while(corr->next!=NULL){
- if (corr->info==x){
- save=prec;
- }
- prec=corr;
- corr=corr->next;
- }
- prec=save->next;
- save->next=save->next->next;
- corr=*l;
- prec->next=corr;
- *l=prec;
- }
- }
- int main(){
- ListaDiElementi l=malloc(sizeof(ElementoDiLista));
- ListaDiElementi corr=l;
- int x=4,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;
- sposta (&l,x);
- stampa(l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement