#include #include #include /* file e-coda.c */ struct Anello { int Val; struct Anello *Prossimo; }; struct Coda { int anelli; struct Anello *primo, *corr, *prox; }; void InizializzaCoda(struct Coda *this) { (*this).anelli=0; }; int AggiornaCoda(struct Coda *this, int num) { this->prox = malloc(sizeof(struct Anello)); (*this->prox).Val = num; this->prox->Prossimo = NULL; if ( (*this).anelli == 0 ) { /* Si salva il primo anello */ (*this).anelli = 1; this->primo = this->prox; } else { this->corr->Prossimo = this->prox; (*this).anelli = (*this).anelli + 1; } this->corr = this->prox; return 0; } int AnelliCoda(struct Coda this) { return this.anelli; } void StampaCoda(struct Coda this) { this.prox = this.primo; do { printf("%d\n",this.prox->Val); if ( this.prox->Prossimo == NULL ) break; this.prox = this.prox->Prossimo; } while (1 ==1); printf("\n"); } int main (){ struct Coda numeri; int i; InizializzaCoda(&numeri); for ( i = 0; i < 10; i++ ) { AggiornaCoda(&numeri, i); } printf("Sono stati inseriti %d numeri:\n",AnelliCoda(numeri)); StampaCoda(numeri); return(0); }